-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCircularLinkedList_withReference.cpp
More file actions
92 lines (86 loc) · 1.56 KB
/
Copy pathCircularLinkedList_withReference.cpp
File metadata and controls
92 lines (86 loc) · 1.56 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
using namespace std;
struct node{
int data;
node* next;
};
void InsertFront(node** tail,int i){
node* temp=new node;
temp->data=i;
if(*tail==NULL){
*tail=temp;
(*tail)->next=*tail;
return;
}
temp->next=(*tail)->next;
(*tail)->next=temp;
return;
}
void InsertEnd(node** tail,int i){
node* temp=new node;
temp->data=i;
if(*tail==NULL){
*tail=temp;
(*tail)->next=*tail;
return;
}
temp->next=(*tail)->next;
(*tail)->next=temp;
(*tail)=temp;
return;
}
void DeleteFront(node** tail){
node* temp=*tail;
node* temp1=*tail;
temp=(temp->next)->next;
temp1=(*tail)->next;
delete(temp1);
temp1=NULL;
(*tail)->next=temp;
}
void DeleteEnd(node** tail){
node* temp=*tail;
node* temp1;
do{
temp1=temp;
temp=temp->next;
}while(temp->next!= (*tail)->next);
temp1->next=(*tail)->next;
delete(temp);
temp=NULL;
*tail=temp1;
}
void Display(node* tail){
node* temp=tail;
do{
temp=temp->next;
cout<<temp->data<<" ";
}while(temp->next!=tail->next);
cout<<endl;
}
int main()
{
node* tail=NULL;
for(int i=0;i<10;i++){
InsertFront(&tail,i);
}
Display(tail);
tail=NULL;
for(int i=0;i<10;i++){
InsertEnd(&tail,i);
}
Display(tail);
int i=0;
while(i!=4){
DeleteEnd(&tail);
i++;
}
Display(tail);
i=0;
while(i!=2){
DeleteFront(&tail);
i++;
}
Display(tail);
return 0;
}