class Node {
int data // variable to store the data of the node
Node next // variable to store the address of the next node
}
class DLLNode {
int val // variable to store the data of the node
DLLNode prev // variable to store the address of the previous node
DLLNode next // variable to store the address of the next node
}
class DLLNode {
int val // variable to store the data of the node
DLLNode prev // variable to store the address of the previous node
DLLNode next // variable to store the address of the next node
class Node{
int data // variable containing the data of the node
Node next // variable containing the address of next node
}
void traversell (Node head) {
while (head != NULL)
{
print(head.data)
head =head . next
}
}
// function is returning the head of the singly linked-list
Node insertAtBegin(Node head, int val)
{
newNode = new Node(val) // creating new node of linked list
if(head == NULL // check if linked list is empty
return newNode
else // inserting the node at the beginning
{
newNode.next =head
return newNode
}
}
// the function is returning the head of the singly linked list
Node insertAtEnd(Node head, int val)
{
if(head ==NULL ) // handing the special case
{
newNode = new Node(val)
head = newNode
return head
}
Node temp = head
// traversing the list to get the last node
while( temp.next !=Null )
{
temp=temp.next
}
newNode=new Node(val)
temp.next=newNode
return head
}
void insertAfter(Node prevNode, int val)
{
newNode= new Node(val)
newNode.next = prevNode.next
prevNode.next=newNode
}
// this function will return the head of the linked list
Node deleteLL(Node head, Node del)
{
if(head == del) // if the node to be deleted is the head node
{
return head.next // special case for the first Node
}
Node temp = head
while( temp.next !=NULL )
{
if(temp.next == del) // finding the node to be deleted
{
temp.next = temp.next.next
delete del // free the memory of that Node
return head
}
temp =temp.next
}
return head // if no node matches in the Linked List
}
bool searchLL(Node head,int val)
{
Node temp =head // creating a temp variable pointing to the head of the linked list
While(temp !=NULL) // traversing the list
}
if( temp.data == val)
return true
temp = temp.next
}
return false
}
void updateLL(Node head,int val, int newVal)
{
Node temp = head
while(temp =head
{
if( temp.data == val)
{
temp.data = newVal
return
}
temp = temp.nexy
}
}
class Node {
int data // variable to store the data of the node
Node next // variable to store the address of the next node
}
class DLLNode {
int val // variable to store the data of the node
DLLNode prev // variable to store the address of the previous node
DLLNode next // variable to store the address of the next node
}
class DLLNode {
int val // variable to store the data of the node
DLLNode prev // variable to store the address of the previous node
DLLNode next // variable to store the address of the next node
class Node{
int data // variable containing the data of the node
Node next // variable containing the address of next node
}
void traversell (Node head) {
while (head != NULL)
{
print(head.data)
head =head . next
}
}
// function is returning the head of the singly linked-list
Node insertAtBegin(Node head, int val)
{
newNode = new Node(val) // creating new node of linked list
if(head == NULL // check if linked list is empty
return newNode
else // inserting the node at the beginning
{
newNode.next =head
return newNode
}
}
// the function is returning the head of the singly linked list
Node insertAtEnd(Node head, int val)
{
if(head ==NULL ) // handing the special case
{
newNode = new Node(val)
head = newNode
return head
}
Node temp = head
// traversing the list to get the last node
while( temp.next !=Null )
{
temp=temp.next
}
newNode=new Node(val)
temp.next=newNode
return head
}
void insertAfter(Node prevNode, int val)
{
newNode= new Node(val)
newNode.next = prevNode.next
prevNode.next=newNode
}
// this function will return the head of the linked list
Node deleteLL(Node head, Node del)
{
if(head == del) // if the node to be deleted is the head node
{
return head.next // special case for the first Node
}
Node temp = head
while( temp.next !=NULL )
{
if(temp.next == del) // finding the node to be deleted
{
temp.next = temp.next.next
delete del // free the memory of that Node
return head
}
temp =temp.next
}
return head // if no node matches in the Linked List
}
bool searchLL(Node head,int val)
{
Node temp =head // creating a temp variable pointing to the head of the linked list
While(temp !=NULL) // traversing the list
}
if( temp.data == val)
return true
temp = temp.next
}
return false
}
void updateLL(Node head,int val, int newVal)
{
Node temp = head
while(temp =head
{
if( temp.data == val)
{
temp.data = newVal
return
}
temp = temp.nexy
}
}