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: 3727576 • 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++11 thank you

Explanation / Answer

Here is the code

/********************/ 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

/*
* DoublyList.h
*
* Created on: 11-Mar-2018
*      Author: tan
*/

#ifndef DOUBLYLIST_H_
#define DOUBLYLIST_H_

#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;

};
#endif /* DOUBLYLIST_H_ */


/***********************/DoublyList.cpp

#include "DoublyList.h"

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 CSCI0"<<head->flight.flightNum << 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
   }
}


/***********************/main.cpp

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

int main() {
   DoublyList* HUFlight = new DoublyList[5];
   FLIGHT fly,fly1;
   fly.destination = "Houston";
   fly.flightNum = 136;
   HUFlight[0].Append(fly);
   fly.destination = "Chicago";
   HUFlight[0].Append(fly);
   fly.destination = "Arizona";
   HUFlight[0].Append(fly);
   fly.destination = "Baltimore";
   HUFlight[0].Append(fly);
   fly.destination = "Detroit";
   HUFlight[0].Append(fly);
   fly.destination = "Denver";
   HUFlight[0].Append(fly);
   fly.destination = "Houston";
   HUFlight[0].Append(fly);

   fly.flightNum = 137;
   fly.destination = "Los Angeles";
   HUFlight[1].Append(fly);
   fly.destination = "Salt Lake City";
   HUFlight[1].Append(fly);

   fly.flightNum = 138;
   fly.destination = "Little Rock";
   HUFlight[2].Append(fly);
   fly.destination = "Wichita";
   HUFlight[2].Append(fly);
   fly.destination = "Indianapolis";
   HUFlight[2].Append(fly);
   fly.destination ="Minneapolis";
   HUFlight[2].Append(fly);

   fly.flightNum = 139;
   fly.destination = "Houston";
   HUFlight[3].Append(fly);
   fly.destination = "Las Alamos";
   HUFlight[3].Append(fly);
   fly.destination = "Las Vegas";
   HUFlight[3].Append(fly);
   fly.destination ="Phoenix";
   HUFlight[3].Append(fly);
   fly.destination ="San Antonio";
   HUFlight[3].Append(fly);

   fly.flightNum = 140;
   fly.destination = "Oakland";
   HUFlight[4].Append(fly);
   fly.destination = "San Diego";
   HUFlight[4].Append(fly);
   fly.destination = "Denvor";
   HUFlight[4].Append(fly);
   fly.destination ="Memphis";
   HUFlight[4].Append(fly);
   fly.destination ="Greenvile";
   HUFlight[4].Append(fly);


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

   for(int i=0;i<5;i++)
   HUFlight[i].Print();
   return 0;
}

/*****************/output

tan@tan-X540LA:~/workspace/DoublyLinkedList/src$ g++ -std=c++11 *.cpp
tan@tan-X540LA:~/workspace/DoublyLinkedList/src$ ./a.out
Flight Records for HowardAir Flight CSCI0136
1. Dallas to Houston
2. Houston to Chicago
3. Chicago to Baltimore
4. Baltimore to Detroit
5. Detroit to Denver
6. Denver to Kansas City
7. Kansas City to Minneapolis
8. Minneapolis to Dallas
Flight Records for HowardAir Flight CSCI0137
1. Los Angeles to Salt Lake City
2. Salt Lake City to Los Angeles
Flight Records for HowardAir Flight CSCI0138
1. Little Rock to Wichita
2. Wichita to Indianapolis
3. Indianapolis to Minneapolis
4. Minneapolis to Little Rock
Flight Records for HowardAir Flight CSCI0139
1. Houston to Las Alamos
2. Las Alamos to Las Vegas
3. Las Vegas to Phoenix
4. Phoenix to San Antonio
5. San Antonio to Houston
Flight Records for HowardAir Flight CSCI0140
1. Oakland to San Diego
2. San Diego to Denvor
3. Denvor to Memphis
4. Memphis to Greenvile
5. Greenvile to Oakland
tan@tan-X540LA:~/workspace/DoublyLinkedList/src$

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