forked from shanilla9605kh/C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathP3.cpp
More file actions
61 lines (57 loc) · 1.33 KB
/
P3.cpp
File metadata and controls
61 lines (57 loc) · 1.33 KB
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
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
struct node
{ int data;
struct node *nxt;
}*head,*newnode,*prenode,*ptr;
void llmake()
{ int i=1;
char j;
head=(struct node *)malloc(sizeof(struct node));
printf("Input data for node %d : ",i);
scanf("%d",&head->data);
head->nxt=NULL;
prenode=head;
printf("\tWant to enter more ? (y/n) : ");
scanf("%s",&j);
while(j=='y')
{ i++;
newnode=(struct node *)malloc(sizeof(struct node));
printf("\nEnter data for node %d : ",i);
scanf("%d",&newnode->data);
newnode->nxt=NULL;
prenode->nxt=newnode;
prenode=newnode;
printf("\tWant to enter more ? (y/n) : ");
scanf("%s",&j);
}
}
void displaycll()
{ int i=1;
ptr=head;
printf("\n\nLinked list is :-\n");
do
{ printf("---------------------------------\n");
printf("| Node | Data | Address | Next |\n");
printf("---------------------------------\n");
printf("| %d | %d | %d | %d |\n",i,ptr->data,ptr,ptr->nxt);
printf("---------------------------------\n");
if(ptr->nxt!=NULL)
{ printf(" |\n");
printf(" v\n");
}
ptr=ptr->nxt;
i++;
delay(750);
}while(ptr!=NULL);
}
void main()
{ clrscr();
printf("LL creation :-\n\n");
llmake();
displaycll();
printf("\nPress any key to EXIT...");
getch();
}