Write A Program in C++ To Delete A Perticular Node From Linked List. Ans
Write A Program in C++ To Delete A Perticular Node From Linked List. Ans
Write A Program in C++ To Delete A Perticular Node From Linked List. Ans
class Node
public:
int data;
Node *next;
};
if(head == n)
if(head->next == NULL)
return;
}
head->data = head->next->data;
n = head->next;
head->next = head->next->next;
free(n);
return;
prev = prev->next;
if(prev->next == NULL)
return;
}
prev->next = prev->next->next;
free(n);
return;
new_node->data = new_data;
new_node->next = *head_ref;
*head_ref = new_node;
while(head!=NULL)
{
cout<<head->data<<" ";
head=head->next;
cout<<endl;
int main()
push(&head,3);
push(&head,2);
push(&head,6);
push(&head,5);
push(&head,11);
push(&head,10);
push(&head,15);
push(&head,12);
printList(head);
cout<<"\nDeleting node "<< head->next->next->data<<" ";
deleteNode(head, head->next->next);
printList(head);
deleteNode(head, head);
printList(head);
return 0;
OUTPUT
2. Write a program in C++ to create a singly linked list of n nodes and
display it in reverse order.
struct node
int t;
node *next;
};
class xyz
private:
int size;
node *head;
public:
xyz()
size=0;
head=new node;
head=0;
~xyz()
newItem=addMe;
newItem->next=head;
head=newItem;
for(int i=0;i<num;i++)
add(pointer);
print=head;
for(int i=0;i<num;i++)
cout<<print->t<<endl;
cout<<endl;
};
int main()
int num;
cout<<"How many elements do you want to insert?"<<endl;
cin>>num;
xyzPointer->addNode(num);
xyzPointer->printMe(num);