forked from anurag1802/Data-Structure-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircularLL.cpp
50 lines (48 loc) · 816 Bytes
/
circularLL.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
#include<iostream>
using namespace std;
struct node{
int data;
struct node *next;
};
struct node *start=NULL, *newnode, *temp, *nextnode;
//*function to create a circular linked list*//
void createCircularLinkedList(void)
{
struct node *newnode;
int choice=1;
while(choice != 0)
{
newnode= new node;
cout<<"Enter data to insert:";
cin>>newnode->data;
newnode->next=NULL;
if(start==NULL)
{
start=temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
temp->next=start;
cout<<"Continue ? 1:YES, 0:NO =>";
cin>>choice;
}
}
//display function //
void display (void)
{
temp = start;
do{
cout<<temp->data;
temp=temp->next;
}
while(temp!=start);
cout<<endl;
}
int main()
{
createCircularLinkedList();
display();
}