Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this partially given C++ program, Please write explanations for bolded lines(what they do) as comments in clear words. Thank you. // Program Code bool
In this partially given C++ program, Please write explanations for bolded lines(what they do) as comments in clear words. Thank you.
// Program Code
bool insertNum(nodeType **first, int num){ // function definition
nodeType *current, *head, *newNode, *prior; head = *first; int done; if(head == NULL){ // insert into empty list head = new nodeType; head->info = num; head->link = NULL; done=1; } else{ // 1.else if(head->info > num){ // insert at top of list newNode = new nodeType; newNode->info = num; newNode->link = head; head=newNode; done = 1; } else{ // 2.else done = 0; current = head; while((current != NULL)&&(!done)){ // insert between two existing nodes if(current->info > num){ newNode = new nodeType; newNode->info = num; newNode->link = current; prior->link = newNode; done = 1; } else{ prior = current; current = current->link; } } // while loop if(!done){ // insert at end of list newNode = new nodeType; newNode->info = num; newNode->link = current; prior->link = newNode; done = 1; } // 2.else } // 1.else } // if *first = head; return done; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started