-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGFG_Circular_Linked_List_Implementation.cpp
More file actions
71 lines (69 loc) · 1.43 KB
/
GFG_Circular_Linked_List_Implementation.cpp
File metadata and controls
71 lines (69 loc) · 1.43 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
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
struct node
{
ll data;
struct node* next;
};
struct node* Insert_tail(struct node* head,ll value)
{
struct node* curr=head;
struct node* new_node=(struct node*)(malloc(sizeof(struct node)));
if(head==NULL)
{
new_node->data=value;
new_node->next=new_node;
head=new_node;
}
else
{
do{
curr=curr->next;
}while(curr->next!=head);
new_node->data=value;
curr->next=new_node;
new_node->next=head;
}
return head;
}
void display(struct node* head)
{
struct node* curr=head;
cout<<"The circular Linked List is:"<<endl;
do{
cout<<curr->data<<" ";
curr=curr->next;
}while(curr!=head);
cout<<"\n";
}
struct node* delete_node(struct node* head, ll value)
{
if(head->data==value)
{
head=head->next;
}
struct node* curr=head;
do{
if(curr->next->data==value)
{
struct node* del=curr->next;
curr->next=curr->next->next;
free(del);
return head;
}
curr=curr->next;
}while(curr!=head);
}
int main()
{
struct node* head=NULL;
head=Insert_tail(head,2);
head=Insert_tail(head,3);
head=Insert_tail(head,6);
head=Insert_tail(head,8);
display(head);
head=delete_node(head,3);
display(head);
}