-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircular_list.cpp
80 lines (77 loc) · 1.56 KB
/
circular_list.cpp
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
#include<iostream>
using namespace std;
struct circular_list
{
struct circular_list*next;
int info;
};
typedef struct circular_list node;
node* insert_end(node*start,int num)
{
node*newnode,*temp;
newnode=(node*)malloc(sizeof(node));
newnode->next=NULL;
newnode->info;
if(start==NULL)
{
start=newnode;
newnode->next=start;
}
else
{
temp=start;
while(temp->next!=start)
{
temp=temp->next;
}
temp->next=newnode;
newnode->next=start;
}
return start;
}
void display(node*start)
{
node*temp;
if(start==NULL)
cout<<"empty list";
else
{
temp=start;
do
{
cout<<temp->info<<"->";
temp=temp->next;
}while(temp->next!=start);
}
}
int main()
{
node*start;
int num,pos,choice;
while(true)
{
cout<<"\n******************* MENU *****************"<<endl;
cout<<"1.insert node @ end"<<endl;
cout<<"5.dispaly list"<<endl;
cout<<"6.exit"<<endl;
cout<<"enter your choice : "<<endl;
cin>>choice;
switch(choice)
{
case 1:
cout<<"enter element to insert :";
cin>>num;
start=insert_end(start,num);
break;
case 5:
display(start);
break;
case 6:
exit(0);
default:
cout<<"invalid input"<<endl;
break;
}
}
return 0;
}