struct DoubleLinkedNode { int data; DoubleLinkedNode * prev; DoubleLinkedNode *
ID: 3757935 • Letter: S
Question
struct DoubleLinkedNode
{
int data;
DoubleLinkedNode * prev;
DoubleLinkedNode * next;
};
// consider the following double linked list:
/**
[NULL][90]->[500][47][75]->[300][75][1000]->[7000]->[62][NULL]
5000 <- 3000 <- 7000 <- 1000
a. what is the value of start->next->next->data
ans: 75
b. given that the numbers below each node are the addresses of the node, fill thes for prev and next for each node in the double linked list.
ans: 3000 5000 7000 3000 1000 7000
c. what is the value of start->next->next->prev->data
ans: 47
d. without introducing any work variables, remove the node containing 75 from the double linked list. no need to return the momeory of the removed node to the heap
*/
write part d
no need for driver program
Explanation / Answer
As there is no need to return the deleted node , we just need to point
remove(list,75)
void remove(DoubleLinkedNode start, int data) {
if(start != null) {
if(start->data == data) {
start = start->next;
start->prev = null;
} else {
while(start->next != null) {
if(start->next->data == data) {
//skip immediate next node
start->next = start->next->next;
//the prev of node which is after the data matched node, should point to previous of data node
start->next->next->prev = start;
break;
}
start = start->next;
}
}
}
}
remove(list,75)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.