forked from nirala96/open_source_start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Linked List.c
74 lines (69 loc) · 1.43 KB
/
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<stdlib.h>
#include <stdio.h>
void create();
void display();
struct Node{
int data;
struct Node *next;
}
*Start =NULL;
int main()
{
printf("This is my first link list program\n");
while(1)
{
int choice;
printf("\nEnter your choice\n1.For creating\n2.For Displaying\n3.For exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:create();
break;
case 2:display();
break;
case 3:exit(0);
}
}
return 0;
}
void create()
{
int a;
do{
struct Node *current,*newnode;
newnode=(struct Node*)malloc(sizeof(struct Node));
printf("\nEnter the data to be entered in the node: ");
scanf("%d",&newnode->data);
newnode->next=NULL;
if(Start==NULL)
{
current=newnode;
Start=newnode;
}
else{
current->next=newnode;
current=newnode;
}
printf("Do you want to continue creating nodes\n1. to continue\n0. to stop: ");
scanf("%d",&a);
}
while(a!=0);
}
void display()
{
struct Node *temp;
temp=Start;
printf("The linked list is: ");
if(Start==NULL)
{
printf("the list is empty\n");
}
else{
while(temp!=NULL)
{
printf("%d ",temp->data);
temp=temp->next;
}
printf("\n");
}
}