-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcll.cpp
76 lines (56 loc) · 1.26 KB
/
cll.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//Circular Linked Lists
//Libraries
#include<bits/stdc++.h>
#include<cstdio>
//namespaces
using namespace std;
//Global Variable Declarations
struct node{
int data;
node * next;
};
struct node * start = NULL;
//Function prototypes
struct node * create_cll(node *);
void display_cll(node *);
//main function
signed main(){
start = create_cll(start);
display_cll(start);
return 0;
}
struct node * create_cll(node *){
node * new_node, *ptr;
cout<<"Enter the data in the new node"<<endl;
cout<<"Enter -404 to terminate the allocation of data"<<endl;
while(true){
new_node=new struct node;
cin>>new_node->data;
if (new_node->data==-404)
break; //Breaks while Loop;
// new_node->next= new_node;
if (start==NULL){
new_node->next= new_node;
start=new_node;
}
else{
ptr=start;
while(ptr->next!=start)
ptr=ptr->next;
ptr->next=new_node;
new_node->next=start;
}
}
return start;
}
void display_cll(node *) {
node * ptr;
ptr=start;
while(true){
cout<<ptr->data;
if(ptr->next==start)
break;
ptr=ptr->next;
}
return;
}