-
Notifications
You must be signed in to change notification settings - Fork 340
/
CircularLL.cpp
51 lines (51 loc) · 1.07 KB
/
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
51
#include<iostream>
#include<conio.h>
using namespace std;
class Node{
public:
int data;
Node *link;
};
Node *head=NULL;
void createNode(){
char ch;
do{
Node *current;
Node *new_node=new Node;
cout<<"\nEnter the data:";
cin>>new_node->data;
new_node->link=NULL;
if (head==NULL){
head=new_node;
current=new_node;
}
else{
current->link=new_node;
current=new_node;
current->link=head;
}
cout<<"\nDo you want to add more nodes?";
ch=getche();
}while(ch!='n');
}
void print(){
Node *new_node;
new_node=head;
if (new_node==NULL){
cout<<"\nLink list is empty.";
}
else{
cout<<"\nData in list is as follows:"<<endl;
cout<<new_node->data<<"\t";
new_node=new_node->link;
while(new_node!=head){
cout<<new_node->data<<"\t";
new_node=new_node->link;
}
cout<<new_node->data<<"\t";
}
}
int main(){
createNode();
print();
}