Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help!! trying to write a code using C++ to add an integer value to the end of a linked list! code isnt working and

please help!!

trying to write a code using C++ to add an integer value to the end of a linked list! code isnt working and i think its specifically due to the else statement.

image text in transcribed

void addIntToEndofList(LinkedList list, int value) t assert (list!=NULL); // if list is NULL, we can do nothing Node *p; // temporary pointer /I TODO: // (1) Allocate a new node. p will point to it. p = new Node; // (2) Set p's data field to the value passed in p->data = value; // (3) Set p's next field to NULL p->next = NULL; if (list->head-NULL) { / (4) Make both head and tail of this list point to p list->headp; list->tail = p; else t // Add p at the end of the list // (5) The current node at the tail? Make it point to p instead of NULL list-tail = p; // (6) Make the tail of the list be p now list->tail->next = p

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions