forked from tanus786/CP-Codes-HackOctober-Fest-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedList.cpp
63 lines (57 loc) · 989 Bytes
/
LinkedList.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
#include <iostream>
using namespace std;
struct node
{
int data;
struct node *next;
}*head=0;
void createCLL()
{
struct node *newnode,*temp;
newnode=(struct node*)malloc(sizeof(struct node));
cout<<"enterdata"<<endl;
cin>>newnode->data;
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else{
temp->next=newnode;
temp=newnode;
}
temp->next=head;
}
void display()
{
struct node *temp;
if(head== 0)
{
cout<<"head empty"<<endl;
}
else{
temp=head;
while(temp->next!=head)
{
cout<<temp->data<<endl;
temp=temp->next;
}
cout<<temp->data<<endl;
}
}
int main()
{
int ch;
do
{ cout<<"enter choice 1:insert 2:display"<<endl;
cin>>ch;
switch(ch)
{
case 1: createCLL();
break;
case 2: display();
break;
default: cout<<"Invalid choice"<<endl;
}
} while (ch!=0);
}