-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkedlist.c
53 lines (44 loc) · 847 Bytes
/
linkedlist.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
/**
* Linked List data structure
* Insert and Print Functions
* Insertion of new node at the beginning of the list
* Prints list in reverse order
* Created at: 02/14/2016
* Created by: Pradyumna Shembekar
*
**/
#include<stdio.h>
#include<stdlib.h>
struct Node {
int data;
struct Node* next;
};
struct Node* head;
void Insert(int dat) {
struct Node* temp = (struct Node*)malloc(sizeof(struct Node));
temp->data = dat;
temp->next = head;
head = temp;
}
void Print() {
struct Node* temp = head;
printf("List is: ");
while(temp != NULL) {
printf("%d ", temp->data);
temp=temp->next;
}
printf("\n");
}
int main() {
head = NULL;
int n,i,dat;
printf("Enter number of elements: \n");
scanf("%d", &n);
printf("Enter elements: \n");
for(i=0;i<n;i+=1) {
scanf("%d", &dat);
Insert(dat);
Print();
}
return 0;
}