-
Notifications
You must be signed in to change notification settings - Fork 6
/
Program - 6.c
138 lines (130 loc) · 3.62 KB
/
Program - 6.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct node
{
int rollno;
char name[15];
struct node *nxt;
} * last, *newnode, *prenode, *ptr;
void addfront()
{
if (last == NULL)
{
last = (struct node *)malloc(sizeof(struct node));
printf("Enter Roll No. : ");
scanf("%d", &last->rollno);
printf("Enter Name : ");
scanf("%s", &last->name);
last->nxt = last;
prenode = last;
}
else
{
newnode = (struct node *)malloc(sizeof(struct node));
printf("\nEnter Roll No. : ");
scanf("%d", &newnode->rollno);
printf("Enter Name : ");
scanf("%s", &newnode->name);
newnode->nxt = prenode;
last->nxt = newnode;
prenode = newnode;
}
}
void displaycircularlist()
{
if (last == NULL)
{
printf("--------------------------------------\n");
printf("List is empty\n");
printf("--------------------------------------\n");
}
else
{
int i = 1;
ptr = last->nxt;
printf("\n\nLinked list is :-\n\n");
printf("-------------------------------------------------------\n");
do
{
printf("Node - %d : Roll No. - %d", i, ptr->rollno);
printf("\n : Name - %s", ptr->name);
printf("\n : Address - %d", ptr);
printf("\n : Next - %d \n", ptr->nxt);
printf("-------------------------------------------------------\n");
ptr = ptr->nxt;
i++;
} while (ptr != prenode);
}
}
int deleteend()
{
if (last == NULL)
{
printf("--------------------------------------\n");
printf("List is empty\n");
printf("--------------------------------------\n");
return 0;
}
else
{
if (last->nxt == last)
{
last = NULL;
}
else
{
ptr = last->nxt;
do
{
ptr = ptr->nxt;
if (ptr->nxt == last)
{
ptr->nxt = last->nxt;
free(last);
last = ptr;
break;
}
} while (ptr != prenode);
}
printf("\n-------------------------------------------\n");
printf("Deleted Successfully.");
printf("\n-------------------------------------------\n");
}
}
void main()
{
int choice;
printf("\n\t -: Student Information :-");
do
{
printf("\n\n-------------------------------------------\n");
printf("\t\t-: Menu :-\n");
printf("-------------------------------------------\n\n");
printf("1. Add Node at Front\n2. Diaplay Circular List\n");
printf("3. Delete Node from End\n4. Exit\n");
printf("\nEnter choice no. : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
addfront();
printf("\n-------------------------------------------\n");
printf("Added Successfully.");
printf("\n-------------------------------------------\n");
break;
case 2:
displaycircularlist();
break;
case 3:
deleteend();
break;
case 4:
break;
default:
printf("\nPlease enter valid choice number !!!");
}
} while (choice != 4);
printf("\nPress any key to EXIT ...");
getch();
}