COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
main3_2.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include "
3.h
"
4
5
int
main
(
int
argc,
char
*argv[]) {
6
int
n = 3;
7
ListNode
* listArray = (
ListNode
*)malloc(n *
sizeof
(
ListNode
));
8
9
ListNode
* listPtr = &listArray[0];
10
listPtr->
data
= 1;
11
listPtr->
next
= NULL;
12
13
listPtr = &listArray[1];
14
ListNode
* newNode1 = (
ListNode
*)malloc(
sizeof
(
ListNode
));
15
ListNode
* newNode2 = (
ListNode
*)malloc(
sizeof
(
ListNode
));
16
listPtr->
data
= 1;
17
listPtr->
next
= newNode1;
18
newNode1->
data
= 2;
19
newNode1->
next
= newNode2;
20
newNode2->
data
= 3;
21
newNode2->
next
= newNode2;
22
23
listPtr = &listArray[2];
24
ListNode
* newNode3 = (
ListNode
*)malloc(
sizeof
(
ListNode
));
25
listPtr->
data
= 1;
26
listPtr->
next
= newNode3;
27
newNode3->
data
= 2;
28
newNode3->
next
= NULL;
29
30
double
average =
findAverageCycleLength
(listArray, n);
31
32
printf(
"%f\n"
, average);
33
34
free(newNode1);
35
free(newNode2);
36
free(newNode3);
37
free(listArray);
38
}
findAverageCycleLength
double findAverageCycleLength(ListNode *arrPtr, int n)
Definition
3.c:4
3.h
main
int main()
Definition
3.cpp:9
listNode
Definition
3.h:4
listNode::data
int data
Definition
3.h:5
listNode::next
struct listNode * next
Definition
3.h:6
Assignment4
P3
main3_2.c
Generated on Sun Sep 29 2024 16:39:53 for COMP2113 by
1.12.0