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