0% found this document useful (0 votes)
11 views1 page

Doubly Linked List Structures

Uploaded by

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

Doubly Linked List Structures

Uploaded by

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

Doubly Linked List Structures

Node *insertAtBegin(Node *head, int x)


{
Node *temp = new Node(x);
temp->next = head;
head->prev = temp;
return temp;
}
Node *insertAtEnd(Node *head, int x)
{
Node *curr = head;
while((curr->next)!=NULL)
{
curr = curr->next;
}
Node *temp = new Node(x);
temp->prev = curr;
curr->next = temp;
return head;
}
Node *reverseList(Node *head)
{
Node *curr = head;
Node *temp;
curr->prev = curr->next;
curr->next = NULL;
curr = curr->prev;
while((curr->next)!=NULL)
{
temp = curr->next;
curr->next = curr->prev;
curr->prev = temp;
curr = curr->prev;
}
curr->next = curr->prev;
curr->prev = NULL;
return curr;
}

Node *deleteHead(Node *head)


{
Node *curr = head;
curr = curr->next;
curr->prev = NULL;
delete head;
return curr;
}
Node *deleteTail(Node *head)
{
Node *curr = head;
while((curr->next->next)!=NULL)
{
curr = curr->next;
}
delete curr->next;
curr->next = NULL;
return head;
}

You might also like