-
Notifications
You must be signed in to change notification settings - Fork 0
/
Linked_List.c
46 lines (41 loc) · 834 Bytes
/
Linked_List.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
#include<stdio.h>
#include<stdlib.h>
struct Node* insert(struct Node*, int);
void print(struct Node*);
struct Node
{
int data;
struct Node* next;
};
struct Node* insert(struct Node* head, int x)
{
struct Node* temp = (struct Node*)malloc(sizeof(struct Node));
temp -> data = x;
temp -> next = head;
head = temp;
return head;
}
void print(struct Node* head)
{
struct Node* temp = head;
printf("The Linked List is:\n");
while(temp != NULL)
{
printf("%d\t", temp -> data);
temp = temp -> next;
}
}
void main()
{
struct Node* head = NULL;
int n, x;
printf("How many numbers?\n");
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
printf("Enter the number:\n");
scanf("%d",&x);
head = insert(head, x);
}
print(head);
}