Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose a program has to maintain a list of flights departing in the next few hours, and we have decided to implement it as a

Suppose a program has to maintain a list of flights departing in the next few hours, and we have decided to implement it as a doubly linked list. A node of the list can be represented as:

struct NODE { FLIGHT flight; NODE *next; NODE *previous; }; struct FLIGHT { int flightNum; string destination; }; 

Create a doubly linked list to hold the initial flight information:

Houston, Chicago, Arizona, Baltimore, Detroit, Denver, Houston

Your program must implement the following methods: Append, Prepend, Remove, InsertAfter, and Print

The Append function, appends data to the end of the list

The Prepend function, prepends data to the beginning of the list

The Remove function, removes a node from the list and adjusts the length of the list

The Print function must print the entire list

Prepend Dallas to the list

Remove Arizona from the list

Append Kansas City to the list

Insert Minneapolis after Kansas City in the list

Remove Houston from the list

Print the flight record using the Example of how your output is supposed to look:

Example:

Flight Records for Flight

Dallas to Houston

Houston to Chicago

Chicago to Baltimore

Baltimore to Detroit

Detroit to Denver

Denver to Kansas City

Kansas City to Minneapolis

Minneapolis to Dalla

must be done in c++ create a double linked list node class and a list class and include a main function must be done in c++

please modfy the node class into a double linked list nodeclass thank you

#include

#include

#include

using namespace std;

class IntNode {

public:

IntNode(int dataInit = 0, IntNode* nextLoc = nullptr);

void InsertAfter(IntNode* nodePtr);

IntNode* GetNext();

void PrintNodeData();

IntNode* Append(int dataVal);

private:

int dataVal;

IntNode* nextNodePtr;

};

// Constructor

IntNode::IntNode(int dataInit, IntNode* nextLoc) {

this->dataVal = dataInit;

this->nextNodePtr = nextLoc;

return;

}

void IntNode::InsertAfter(IntNode* nodeLoc) {

IntNode* tmpNext = nullptr;

tmpNext = this->nextNodePtr; // Remember next

this->nextNodePtr = nodeLoc; // this -- node -- ?

nodeLoc->nextNodePtr = tmpNext; // this -- node -- next

return;

}

// Print dataVal

void IntNode::PrintNodeData() {

cout << this->dataVal << endl;

return;

}

// Grab location pointed by nextNodePtr

IntNode* IntNode::GetNext() {

return this->nextNodePtr;

}

IntNode* IntNode::Append(int dataVal)

//COMMENT EACH LINE BELOW

{

IntNode* head;

IntNode *last = new IntNode;

last->dataVal = dataVal;

last->nextNodePtr = NULL;

if (head == NULL) {

head = last;

}

else {

IntNode *temp = new IntNode;

temp = head;

while (temp->nextNodePtr != NULL) {

temp = temp->nextNodePtr;

}

temp->nextNodePtr = last;

}

return head;

}

int main() {

srand(time(0));

IntNode* headObj = nullptr; // Create intNode objects

IntNode* nodeObj1 = nullptr;

IntNode* nodeObj2 = nullptr;

IntNode* nodeObj3 = nullptr;

IntNode* nodeObj4 = nullptr;

IntNode* nodeObj5 = nullptr;

IntNode* nodeObj6 = nullptr;

IntNode* nodeObj7 = nullptr;

IntNode* nodeObj8 = nullptr;

IntNode* nodeObj9 = nullptr;

IntNode* nodeObj10 = nullptr;

IntNode* currObj = nullptr;

int i;

IntNode test;

// Front of nodes list

headObj = new IntNode((rand() % 51) + 50);

for (i = 0; i < 9; i++) {

nodeObj1 = new IntNode((rand() % 51) + 50);

headObj->InsertAfter(nodeObj1);

}

test.Append(16);

// Print linked list

currObj = headObj;

while (currObj != nullptr) {

currObj->PrintNodeData();

currObj = currObj->GetNext();

}

return 0;

}

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

Real Time Database Systems Architecture And Techniques

Authors: Kam-Yiu Lam ,Tei-Wei Kuo

1st Edition

1475784023, 978-1475784022

More Books

Students also viewed these Databases questions

Question

why do consumers often fail to seek out higher yields on deposits ?

Answered: 1 week ago