-
Notifications
You must be signed in to change notification settings - Fork 13
/
Linked_list
48 lines (42 loc) · 828 Bytes
/
Linked_list
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
#include <stdio.h>
//Compiler version gcc 6.3.0
struct node{
int data;
struct node *next;
};
struct node *head;
void push(int data){
struct node *temp = (struct node*)malloc(sizeof(struct node));
if(temp==NULL){
printf("overflow");
}
else{
if(head == NULL){
temp->data = data;
temp->next = NULL;
head = temp;
}
else{
temp->data = data;
temp->next = head;
head = temp;
}
printf("Items pushed!\n");
}
}
int main()
{
struct node *head = (struct node *)malloc(sizeof(struct node));
struct node *ptr = (struct node *)malloc(sizeof(struct node));
head->data = 7;
head->next = NULL;
int value;
scanf("%d",&value);
push(value);
ptr = head;
while(ptr != NULL){
printf("%d -> ",ptr->data);
ptr = ptr->next;
}
return 0;
}