#include \"inlab6.h\" #include \"structs.h\" #include <iostream> #include <fstre
ID: 3553658 • Letter: #
Question
#include "inlab6.h"
#include "structs.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
// This function appends the record 'newData' into the sorted position of the linked list.
// If the list is empty, the new node is the new head of the list.
void ListClass::insertInOrder(RecordType newData)
// INOUT IN
{
NodePtrType newNode, prev,current;//pointers to the new node and for
//traversing the list
// Create a new node to hold the record. Be sure to put
// the data from newData into the newNode.
//The following code should do the following:
//if (expression to check if the list is empty)
//{
// code to make the new node the head of the list
//}
//The following code should do the following:
//else if (expression to check if the new acctNum is less than the head accNum)
//{
// code to make the new node the head of the list
//}
else
{
// put the new node where it belongs.
//Replace this with the code necessary to insert the new node into the list
}
}//end of insertInOrder function
Explanation / Answer
TextBox1:-
newNode = new Node();
newNode->data = newData;
TextBox2:-
if(head == NULL) {
head = newNode;
}
TextBox3:-
else if((head->data).acctNum > newData.acctNum) {
newNode->next = head;
head = newNode;
}
TextBox4:-
current = head->next;
prev = head;
while(current != NULL) {
if((current->data).acctNum > newData.acctNum) {
break;
} else {
prev = current;
current = current->next;
}
}
TextBox5:-
newNode->next = current;
prev->next = newNode;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.