0% found this document useful (0 votes)
10 views

Circular Linked List Table Dsa

The document discusses four functions for performing operations on single and double circular linked lists: insertNodeAtHead, insertNodeAtEnd, deleteNodeAtHead, and deleteNodeAtEnd. The functions add or remove nodes from the beginning or end of the lists respectively.

Uploaded by

hamillisa52
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Circular Linked List Table Dsa

The document discusses four functions for performing operations on single and double circular linked lists: insertNodeAtHead, insertNodeAtEnd, deleteNodeAtHead, and deleteNodeAtEnd. The functions add or remove nodes from the beginning or end of the lists respectively.

Uploaded by

hamillisa52
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Insert at begin Insert at end Delete at begin Delete at end

Node* insertHead(Node *head, int x){ Node *insertEnd(Node *head, int x){ Node* delHead(Node *head){ Node*delend(Node*head){
Node *temp = new Node(x); Node *temp = new Node(x); if(head == NULL) if(head==NULL)return NULL;
if(head == NULL) if(head == NULL){ return NULL; if(head->next==NULL){
temp -> next = temp; temp -> next = temp; if(head -> next ==head){ delete(head);
else{ } delete head; return NULL;
Node *curr = head; else{ return NULL; }
Single while(curr->next != head) Node *curr = head; } else{
curr = curr->next; while(curr->next != head){ Node *curr = head; Node*curr=head->next;
Circular
curr-> next = temp; curr = curr->next; while(curr->next !=head) while(curr->next>next!=head){
linked list temp->next = head; } curr = curr->next; curr=curr->next;
} curr-> next = temp; curr->next = head->next; }
return temp; temp->next = head; delete head; Node*temp=curr->next;
} return head; return (curr->next); delete(temp);
} } curr->next=head;
} return head;
}
}

Node *insertHead(Node *head, int x){ Node *insertEnd(Node *head, int x){ Node* delHead(Node *head){ Node*delend(Node*head){
Node *temp=new Node(x); Node *temp = new Node(x); if(head == NULL) if(head==NULL)return NULL;
if(head==NULL){ if(head == NULL){ return NULL; if(head->next==NULL){
temp->next=temp; temp -> next = temp; if(head -> next ==head){ delete(head);
temp->prev=temp; } delete head; return NULL;
return temp; else{ return NULL; }
Double } Node *curr = head; } else{
Circular temp->prev=head->prev; while(curr->next != head){ Node *curr = head; Node*curr=head;
temp->next=head; curr = curr->next; while(curr->next !=head) while(curr->next!=head){
linked list head->prev->next=temp; } curr = curr->next; curr=curr->next;
head->prev=temp; curr-> next = temp; curr->next = head->next; }
return temp; temp->next = head; head->next->prev=curr; curr->prev->next=head;
} temp -> prev = curr; delete head; delete curr ;
return head; return (curr->next); return head;
} }
} }
}

You might also like