-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinked_list.c
executable file
·59 lines (43 loc) · 1016 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
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<stdio.h>
#include<stdlib.h>
#define null 0
struct link {
int data; // Data element
struct link* next; // Pointer to the next node
};
typedef struct link list;
list *head=null, *p;
void main (){
add();
display();
}
void add(){
int op=1;list*t;
while (op==1)
{
p=((list*)malloc(sizeof(list)));
printf("\nEnter Data To Add: ");
scanf("%d",&p->data);
if (head==null){
head=p;
p->next=null;
t=p;
}
else{
t->next=p;
p->next=null;
t=p;
}
printf("Do you want to add more?");
scanf("%d",&op);
}
}
void display(){
list *i;
int c=0;
for(i=head;i!=null;i=i->next){
c=c+1;
printf("\n%d is the data , %d is the node number,and %x is the address",i->data,c,i);
}
printf("\n%d is the total number of nodes",c);
}