-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircular_LL.cpp
More file actions
52 lines (48 loc) · 836 Bytes
/
Circular_LL.cpp
File metadata and controls
52 lines (48 loc) · 836 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
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include"Node1.cpp"
using namespace std;
Node1* takeInput(){
int dt;
cin>>dt;
if(dt==-1){
return NULL;
}
Node1 *head=NULL,*tail=NULL;
Node1 *newnode=new Node1(dt);
if(head==NULL ){
head=newnode;
tail=newnode;
}
cin>>dt;
while(dt!=-1){
Node1 *newnode=new Node1(dt);
tail->next=newnode;
tail=newnode;
cin>>dt;
}
tail->next=head;
return head;
}
void print(Node1 *head)
{
if(head==NULL)
{
cout<<"\nSorry no Linked List....\n";
return;
}
Node1 *temp=head;
head=head->next;
cout<<temp->a<<" ";
while(head!=temp)
{
cout<<head->a<<" ";
head=head->next;
}
cout<<endl;
}
int main()
{
Node1 *ptr=takeInput();
print(ptr);
return 0;
}