Creating an appointment scheduling program using queue doubly linked lists

I am trying to create a code to create an appointment at a hair salon using queue doubly linked list. The hours of operation of the hair salon is from 9:00am-4:00pm and each appointment takes an hour. The clients choose the time slots themselves and the code is supposed to let them know if a slot has been taken up or all of the time slots have been filled. I have created the structure for the program but I am having a hard time implementing the doubly linked list to print, count, or tell if the list is full.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include <iostream>
  using namespace std;

  struct DeqNode {
  int appStartTime;
  int appEndTime;
  string cusName;
  DeqNode* prevNode;
  DeqNode* nextNode;
  };

  int main()
  {
    DeqNode* array;

    return 0;
  }
first of all why, if you know how many appointments you can have why wouldn't you just use an array?
for running through a doubly linked list you check if the next pointer is nullptr (which it should be initialized to). That's assuming you aren't using a circular list for some reason. I would just use an array though.
Hello vaughanthedon,

Like yem I was thinking of using a vector and if you can not use a vector an array would work than a linked list. The linked list is more work than you need.

So, unless the linked list is a requirement consider something else.

Here is an idea for a start:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct Appointment
{
    bool taken{};
    int appStartTime{};
    int appEndTime{};
    string cusName;
};

int main()
{
    std::vector<Appointment> day(7);  // <--- Size will depend on if last apt. is at 15:00, (7), or 16:00, (8).

    for (size_t idx = 0, startTime = 9; idx < day.size(); idx++, startTime++)
    {
         //<--- Use "idx" to index the vector. Use "startTime" to set "appStarttTime" and "appEndTime".
        // These 2 variables will always have the same values for a given day.
    }
}

I feel this would be much more flexible to upgrade than a linked list would be. It would be very easy to make a 2D vector or even a 2D array to book for more than 1 day.

Something to consider.

Andy
I was thinking a vector would be more acceptable as well. Unfortunately a linked list is required in the code for it to be accepted which is why I’m having such a difficult time implementing it.
Are you required to implement your own linked list, or can you use C++ std::list - or even C++ std::queue?

http://www.cplusplus.com/reference/queue/queue/
http://www.cplusplus.com/reference/list/list/
Last edited on
Hello vaughanthedon,

I feel it would be a good idea if you post the full instructions that you were given for this assignment. This way everyone will know what is allowed and what is not.

When I read
using queue doubly linked list.
I am a bit confused because a "queue" and "doubly linked list" are 2 different concepts.

To start with in "main" you will either the code to create the full linked list or a function to do this. Also "main" should contain the variables "head" and "tail" to access the linked list, so that you have a starting position to deal with the list.

Since you will will be using "new" to create memory for the linked list be sure to use "delete" to free the memory created with "new" when you are done with it or before the close of the program.

Andy
I agree with Handy Andy, it will definitely be helpful if you post the exact requirements, but from what I'm hearing from you is the assignment basically to implement an array using linked list?
If so my personal preference would be to just create an index operator so that you can just treat it like an array.
And if you modify that code in the above sample to bring it into line with 'normal' C++ you have the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// CPP code to implement priority
// queue using doubly linked list

#include <iostream>

// Linked List Node
struct Node {
    int info;
    int priority;
    struct Node *prev, *next;
};
  
// Function to insert a new Node
void push(Node** fr, Node** rr, int n, int p)
{
    Node* news = new Node;
    news->info = n;
    news->priority = p;
  
    // If linked list is empty
    if (*fr == nullptr) {
        *fr = news;
        *rr = news;
        news->next = nullptr;
    }
    else {
        // If p is less than or equal front
        // node's priority, then insert at
        // the front.
        if (p <= (*fr)->priority) {
            news->next = *fr;
            (*fr)->prev = news->next;
            *fr = news;
        }
  
        // If p is more rear node's priority,
        // then insert after the rear.
        else if (p > (*rr)->priority) {
            news->next = nullptr;
            (*rr)->next = news;
            news->prev = (*rr)->next;
            *rr = news;
        }
  
        // Handle other cases
        else {
  
            // Find position where we need to
            // insert.
            Node* start = (*fr)->next;
            while (start->priority > p)
                start = start->next;
            (start->prev)->next = news;
            news->next = start->prev;
            news->prev = (start->prev)->next;
            start->prev = news->next;
        }
    }
}
  
// Return the value at rear
int peek(Node *fr)
{
    return fr->info;
}
  
bool isEmpty(Node *fr)
{
    return (fr == nullptr);
}
  
// Removes the element with the
// least priority value form the list
int pop(Node** fr, Node** rr)
{
    Node* temp = *fr;
    int res = temp->info;
    (*fr) = (*fr)->next;
    delete temp;
    if (*fr == nullptr)
       *rr = nullptr;
    return res;
}
  
// Driver code
int main()
{
    Node *front = nullptr, *rear = nullptr;
    
    push(&front, &rear, 2, 3);
    push(&front, &rear, 3, 4);
    push(&front, &rear, 4, 5);
    push(&front, &rear, 5, 6);
    push(&front, &rear, 6, 7);
    push(&front, &rear, 1, 2);
  
    std::cout << pop(&front, &rear) << std::endl;
    std::cout << peek(front) << '\n';
  
    return 0;
}



1
2
Program ended with exit code: 0

Without going through the exercise it wouldn't take much to adapt this to the hair situation.
Topic archived. No new replies allowed.