-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircularLL.cxx
More file actions
39 lines (38 loc) · 887 Bytes
/
CircularLL.cxx
File metadata and controls
39 lines (38 loc) · 887 Bytes
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
#include<iostream>
using namespace std;
struct Node{
int data;
Node *next;
}*tail;
int main(){
int ch;
struct Node *temp,*newNode;
// head = 0;
do{
newNode = (struct Node *)malloc(sizeof(struct Node));
cout<<"Enter Data: ";
cin>>newNode->data;
newNode->next = 0;
if(tail == 0){
tail = newNode;
tail->next = newNode;
}
else{
newNode->next = tail->next;
tail->next = newNode;
tail = newNode;
}
// tail->next = head;
cout<<newNode->data<<" entered succesfully.";
cout<<"Enter choice: ";
cin>>ch;
}while(ch);
cout<<"\nlinked list data is ";
temp = tail->next;
while (temp->next != tail->next)
{
cout<<temp->data<<"\t";
temp = temp->next;
}
cout<<temp->data<<endl;
}