-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_linkedlist.c
More file actions
46 lines (35 loc) · 791 Bytes
/
task_linkedlist.c
File metadata and controls
46 lines (35 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <sys/time.h>
struct Node
{
double data;
struct Node* next;
};
void loop(struct Node* head)
{
printf("%f -> ",head->data);
while(head->next!=NULL)
{
printf("%f -> ",head->next->data);
head = head->next;
}
}
int main()
{
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
// allocate 3 nodes in the heap
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
head->data = 1.0;
head->next = second;
second->data = 2.0;
second->next = third;
third->data = 3.0;
third->next = NULL;
loop(head);
}