-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinked-list-operations-1.c
65 lines (54 loc) · 2.58 KB
/
linked-list-operations-1.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<stdio.h>
#include<stdlib.h>
struct Node {
int val;
struct Node *next;
};
struct Node *head;
void insert(int);
void print();
int main()
{
head = NULL;
int inp;
for (int i = 0; i < 10; i++)
{
printf("Enter: ");
scanf("%d", &inp);
insert(inp);
}
print();
}
void insert(int num)
{
struct Node *temp = (struct Node*) malloc(sizeof(struct Node));
int inp;
temp -> val = num;
temp -> next = head;
head = temp;
}
void print()
{
struct Node *temp = head;
printf("The List is: ");
while (temp -> next != NULL)
{
printf("%d, ", temp -> val);
temp = temp -> next;
}
printf("\n");
}
/* Output:
Enter: 12
Enter: 45
Enter: 65
Enter: 87
Enter: 98
Enter: 36
Enter: 38
7Enter: 9
Enter: 72
Enter: 18
The List is: 18, 72, 79, 38, 36, 98, 87, 65, 45,
...Program finished with exit code 0
*/