Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose a program has to maintain the flight lists for all of the flights depart

ID: 3727569 • Letter: S

Question

Suppose a program has to maintain the flight lists for all of the flights departing for an airline called HowU Air. You have decided to implement the flight lists as a doubly linked list. However, you have decided to hold all of the flights for your airline in an array because you know that five flights have taken off from various cities within the past 24 hours. A node of the list can be represented as:

Create an array to hold five flight lists as shown below:

NOTE EVERY FLIGHT LIST ENDS IN THE CITY WHERE IT BEGAN

Dallas, Houston, Chicago, Baltimore, Detroit, Denver, Kansas City

Los Angeles, San Francisco, Salt Lake City

Little Rock, Wichita, Minneapolis

Houston, Las Alamos, Las Vegas, Phoenix

Oakland, San Diego, Denver, Memphis, Greenville

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

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 InsertAfter function, inserts a node after another node in your list

The PrintList function must print an entire doubly linked list

The PrintAirlineInfo function must print all the flight lists. The name of the Gate is Gate 56.

For list number 1, Prepend Atlanta to the list

For list number 2, Remove San Francisco

For list number 3, Insert Indianapolis to the list after Wichita

For list number 4, Append San Antonio to the list

List 5 remains the same.

Example Output for all of the flight lists for Gate 56 are below:

code i already have

/main.cpp

#include<iostream>
#include <string>
using namespace std;
#include "NODE.h"
#include "DoublyList.cpp"


DoublyList::DoublyList() {
   this->head = nullptr;
   this->tail = nullptr;
}
void DoublyList::InsertAfter(FLIGHT flight, int target, DoublyList * HUFlight, FLIGHT new_flight) {
   NODE *newbie = new NODE;
   newbie->flight = new_flight;
   NODE* curNode = head;

   while (curNode != nullptr) {
       if (curNode->flight.destination == flight.destination) {
           target--;
          
           if (target == 0) {
               if (curNode == tail) {
                   //if we have found ourselves at the tail, might as well call the Append function
                   HUFlight->Append(new_flight);
                   break;
               }
               else {

                   newbie->next = curNode->next;//connect new node to
                   curNode->next = newbie;
                   newbie->previous = curNode;
                   curNode = curNode->next;
                   curNode->previous = newbie;
                  
                   break;
               }
           }
       }
       curNode = curNode->next;
       if (curNode == head) {
           break;
           //breaks after hitting head the second time
       }
   }
}
void DoublyList::Remove(string place, int target) {

   NODE* curNode = head;
   while (curNode != nullptr) {
       // because this is a circular linked list
       if (curNode->flight.destination == place) {

           target--;
          
           if (target == 0) {
               (curNode->next)->previous = curNode->previous;
               (curNode->previous)->next = curNode->next;
               break;
               //connects previous and next node to each other
           }
           if (curNode == tail) {
               tail = curNode->previous;
               //if it is that we had removed the tail, we set it to the previous node

           }
           else if (curNode == head) {
               head = curNode->next;
               //if it is that we had removed the head, we set it to the next node
           }
       }
       curNode = curNode->next;
       if (curNode == head) {
           break;
           //breaks after hitting head the second time
       }
   }
}
void DoublyList::Prepend(FLIGHT flight) {

   NODE *current = new NODE;
   current->flight = flight;

   if (head == NULL) {
       // if nothing in list it points head and tail to new node
       current->next = nullptr;
       head = current;
       tail = current;
   }
   else {
       current->next = head;
       head->previous = current;
       head = current;
       current->previous = tail;
                              
   }
}
void DoublyList::Append(FLIGHT flight) {
   NODE *current = new NODE;
   current->flight = flight;

   if (head == NULL) {
       // if nothing in list it points head and tail to new node
       current->next = nullptr;
       head = current;
       tail = current;
   }
   else {
       current->previous = tail;
       tail->next = current;
       tail = current;
       current->next = head;
                          
   }
}
void DoublyList::Print() {
   int count = 1;
   NODE* curNode = head;
   string first_place;
   first_place = curNode->flight.destination;
   curNode = head->next;
   cout << "Flight Records for HowardAir Flight CSCI0136:" << endl;
   while (curNode != NULL) {
       cout << count << ". " << first_place << " to " << curNode->flight.destination << endl;
       if (curNode == head) {
           break;
           //breaks after hitting head the second time
       }
       first_place = curNode->flight.destination;
       count++;
       curNode = curNode->next;//Traverses list
   }
}

int main() {
   DoublyList * HUFlight = new DoublyList;
   FLIGHT fly, fly1;
   fly.destination = "Houston";
   fly.flightNum = 0136;
   HUFlight->Append(fly);
   fly.destination = "Chicago";fly.flightNum = 0136;
   HUFlight->Append(fly);
   fly.destination = "Arizona";fly.flightNum = 0136;
   HUFlight->Append(fly);
   fly.destination = "Baltimore";fly.flightNum = 0136;
   HUFlight->Append(fly);
   fly.destination = "Detroit";fly.flightNum = 0136;
   HUFlight->Append(fly);
   fly.destination = "Denver";fly.flightNum = 0136;
   HUFlight->Append(fly);
   fly.destination = "Houston";fly.flightNum = 0136;
   HUFlight->Append(fly);


   //Below are steps instructed to execute
   fly.destination = "Dallas";fly.flightNum = 0136;
   HUFlight->Prepend(fly);
   HUFlight->Remove("Arizona", 1);fly.flightNum = 0136;
   fly.destination = "Kansas City";fly.flightNum = 0136;
   HUFlight->Append(fly);
   fly1.destination = "Minneapolis";fly.flightNum = 0136;
   HUFlight->InsertAfter(fly, 1, HUFlight, fly1);
   HUFlight->Remove("Houston", 2);fly.flightNum = 0136;

   HUFlight->Print();
   return 0;
}
------------------------------------------------------------------------------------------------------------------
//DoublyList.cpp
#include<iostream>
using namespace std;
#include "NODE.h"
class DoublyList {
public:
   DoublyList();
   void Remove(string place, int target);
   void InsertAfter(FLIGHT flight, int target, DoublyList * HUFlight, FLIGHT new_flight);
   void Append(FLIGHT flight);
   void Prepend(FLIGHT flight);
   void Print();
private:
   NODE * head = NULL;
   NODE* tail = NULL;

};
----------------------------------------------------------------------------------------------------------------
//Node.h
#ifndef NODE_H
#define NODE_H
#include<iostream>
using namespace std;

struct FLIGHT {
   int flightNum;
   string destination;
};

struct NODE {
   FLIGHT flight;
   NODE *next;
   NODE *previous;
};

#endif //!NODE_H

it must be done in c++

Explanation / Answer

here is your main file : ----------->>>>>>>>>>

#include<iostream>

using namespace std;

int main(){
DoublyList *airFlight = new DoublyList[5];
FLIGHT f1;
//for first element of the array of list
f1.flightNum = 0136;
f1.destination = "Atlanta";
airFlight[0].append(f1);
f1.destination = "Dallas";
airFlight[0].append(f1);
f1.destination = "Houstan";
airFlight[0].append(f1);
f1.destination = "Chicago";
airFlight[0].append(f1);
f1.destination = "Baltimore";
airFlight[0].append(f1);
f1.destination = "Detroit";
airFlight[0].append(f1);
f1.destination = "Denver";
airFlight[0].append(f1);
f1.destination = "Kanas City";
airFlight[0].append(f1);
f1.destination = "Atlanta";
airFlight[0].append(f1);

//for second element of the array;
f1.flightNum = 0137;
f1.destination = "Los Angeles";
airFlight[1].append(f1);
f1.destination = "Lake City";
airFlight[1].append(f1);
f1.destination = "Los Angeles";
airFlight[1].append(f1);

//for third element of the array
f1.flightNum = 0138;
f1.destination = "Little Rock";
airFlight[2].append(f1);
f1.destination = "Wichita";
airFlight[2].append(f1);
f1.destinazion = "Indianapolis";
airFlight[2].append(f1);
f1.destination = "Minneapolis";
airFlight[2].append(f1);
f1.destination = "Little Rock";
airFlight[2].append(f1);

//for Fourth element of the array
f1.flightNum = 0139;
f1.destination = "Houstan";
airFlight[3].append(f1);
f1.destination = "Las Alamos";
airFlight[3].append(f1);
f1.destination = "Las Vegas";
airFlight[3].append(f1);
f1.destination = "Phoenix";
airFlight[3].append(f1);
f1.destination = "Antonio";
airFlight[3].append(f1);
f1.destination = "Houstan";
airFlight[3].append(f1);

//for Fifth element of the array
f1.flightNum = 0140;
f1.destination = "Oakland";
airFlight[4].append(f1);
f1.destination = "San Deigo";
airFlight[4].append(f1);
f1.destination = "Denver";
airFlight[4].append(f1);
f1.destination = "Memphis";
airFlight[4].append(f1);
f1.destination = "Greenville";
airFlight[4].append(f1);
f1.destination = "Oakland";
airFlight[4].append(f1);


for(int i = 0;i<5;i++){
  airFlight[i].print();
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote