forked from trivedi4u/hacktoberfest24_projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.cpp
More file actions
36 lines (35 loc) · 921 Bytes
/
.cpp
File metadata and controls
36 lines (35 loc) · 921 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
class Solution {
public:
Node* reverse(Node* head) {
// code here
Node *curr=head->next, *prev=head, *nxt=NULL;
while(curr!=head){
nxt=curr->next;
curr->next=prev;
prev=curr;
curr=nxt;
}
head->next=prev;
return prev;
}
// Function to delete a node from the circular linked list
Node* deleteNode(Node* head, int key) {
// code here
Node *temp = head->next, *prev=head;
if(head->data==key){
while(temp!=head){
prev=temp;
temp=temp->next;
}
}
else{
while(temp!=head and temp->data!=key){
prev=temp;
temp=temp->next;
}
}
if(head->data==key or temp!=head)
prev->next=temp->next;
return head->data==key?prev->next:head;
}
};