-
Notifications
You must be signed in to change notification settings - Fork 2
/
LinkedList.c
58 lines (58 loc) · 1.2 KB
/
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
54
55
56
57
58
// make a linked list
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
}*start,*cn;
void createNode()
{
struct node *newNode;
newNode=(struct node*)malloc(sizeof(struct node));
if (newNode==NULL)
{
printf("unable to allocate the memory to newNode!");
exit(1);
}
printf("enter the data : ");
scanf("%d",&newNode->data);
fflush(stdin);
newNode->next=NULL;
start=newNode;
}
void printList()
{
cn=start;
while (cn != NULL)
{
printf("the data in node is %d \n",cn->data);
cn=cn->next;
}
}
int main()
{
char ch;
int choice;
do
{
printf("1. create first node.\n");
printf("2. print list.\n");
printf("enter ur choice :");
scanf("%d",&choice);
fflush(stdin);
switch (choice)
{
case 1:createNode();
break;
case 2: printList();
break;
default:printf("there is no choice like this !");
break;
}
printf("do u want to continue[y/Y] ? : ");
scanf("%c",&ch);
fflush(stdin);
} while (ch=='y' || ch=='Y');
return 0;
}