I need help in implementing the append function correctly to that the program ca
ID: 3884472 • Letter: I
Question
I need help in implementing the append function correctly to that the program can compile and run without any errors. Can you look over my append function in RevNode.h and see what I'm missing? Can you write the correct code down?
glar linked_ists3 - Microsoft VisualC2010 Express File Edit view Praject Debug Taals Windaw selution Lcalorer reverse linked Ists.cpp Urknown Scape) Soluticn 'regular linked Jists3' 1 p #1fndef Revhode h ddefine Revtade regular linked lists3 /i Define the Node struct beloN struct Nodr Hcoder Filcs targetver.h Resource Hiles int data; Node next; Node prows 1,Sourco Files regular nked lists3pp stelafx.cpp ReadMetxt Define the append function belon void append Node head, int value) Node n-Nod) n-dat value; n-nextNULL; -Sprev-NULL Node" curr = head; while (curr-nextNULL) currurr>next; curr->next n Do t write ay ode belo this lirie dundif Readty 1 12 Col 36 Ch 36 INS 4:04 PM Type here to search 9/14/2017Explanation / Answer
Please find my correct implementation of "append" function.
Pelase let me know in case of any issue.
void append(Node **head, int value) {
// creating new node
Node *newNode = new Node();
// setting up data and link
newNode->data = value;
newNode->next = NULL;
newNode->prev = NULL;
Node *last = *head;
// if list is empty, then newNode is new node
if(*head == NULL) {
*head = newNode;
return;
}
// moving 'last' to at last
while(last->next != NULL)
last = last->next;
// appending newNode at last
last->next = newNode;
newNode->prev = last;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.