C++
Assumption and Terminology:
Forward Linked List FLL has "head"
Doubly Linked List DLL has "head" and "tail"
Each node in FLL has "next"
Each node in DLL has "next" and "prev"
Q1: Complete the following constructor code for FLL
FLL::FLL() {
Q2: Complete the FLL insert-front code (which insert node new at the front of FLL)
FLL::insert-front( node * new) {
Q3: Complete the DLL insert-after code (which insert node new after node p)
DLL::insert-after(node *p, node *new) {
Sol.
Ans 1.
FLL::FLL() : head(0) {
head->next = NULL;
}
Ans 2.
FLL::insert_front( node* head, node * new, int data) {
new->data= data;
new->next = head;
head = new;
}
Ans 3.
DLL::insert_after(node *p, node *new, int data) {
if(p == NULL){
cout<<"Cannot add becuase given node p is NULL";
return;
}
new->data = data;
new->next = p->next;
p->next = new;
new->tail = p;
if(new->next!=NULL) // change the tail of the node's next node.
new->next->tail = new;
}
pleazzzzzzzzzz upvote......
Get Answers For Free
Most questions answered within 1 hours.