Circular Linked List Table Dsa
Circular Linked List Table Dsa
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;
} }
} }
}