Hi All,

I was assigned to code a project which to some extend simulates timetable of an airport. This has to be implemented using linkedLists. The poject should consist of Node class and SLL (singly linked list) class. The logic of the project is like this: There should be a clock which ticks every 15 minutes in the main function; I created flight.h file and included all the information related to a flight within. What confuses me here is just some parts of the code related to mergeSort and quickSort.
The project asks to sort all the flights: 1. based on their departure time 2. bases on their departure city.

#include <iostream>
#include <string>

using namespace std;
//
#ifndef FLIGHT_H_
#define FLIGHT_H_

class Node
{
public:
    enum flight_status {On_time, Delayed, Departed};
    struct Time {int hour, minutes;};
    // Default Constructor
    Node () {next = NULL;}
    string airLine;
    int flightNum;
    string city;
    int gate;
    struct Time time;
    flight_status status;
    Node *next;
};
//
class SLL // Singly Linked List
{
public:
    // Default Constructor
    SLL()
    {
        head = new Node;
        head = tail = NULL;
        size = 0;
    }
    // member functions
    void push();
    void print(Node *head);
    void split(Node *head, int left, int right);
    void mergeSort(Node *head, int left, int mid, int right);
    void quickSort(Node *head, int left, int mid, int right);
private:
    Node *head, *tail;
    int size;
};
//
#endif /* FLIGHT_H_ */

I'm thinking about building the rest of the program on top of this declaration. what I want to make sure about is my approach to solve the sorting problem is good according to this implementation of classes.
Thanks in advance.

Recommended Answers

All 3 Replies

Looks fine to me. Though if you're not required to implement quicksort, I'd recommend simply using merge sort. Merge sort is better suited to linked lists because it doesn't require random access. Quicksort on a linked list is tricky to implement efficiently due to the random access component, especially if you're using a singly linked list.

Thanks Deceptikon, Do you mind If I ask you for further help? Please I really need it.

There's not a post limit on threads. Feel free to ask subsequent related questions here. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.