Skip to content

Instantly share code, notes, and snippets.

@story645
Last active May 23, 2019 17:15
Show Gist options
  • Save story645/8fcd28d5c79a2a2c98bb47f36f457422 to your computer and use it in GitHub Desktop.
Save story645/8fcd28d5c79a2a2c98bb47f36f457422 to your computer and use it in GitHub Desktop.

Using the linked list class from homework 3, implement a queue class with the following methods:

  1. push
  2. pop
  3. front
  4. back

Then use that queue to solve the following problem:

Write a simulation program of the lines at a grocery store. The program will be similar to the car wash simulation, except that there are multiple queues instead of one. You might use a vector of queues to simulate the lines. Assume that there are five cashier lines at the grocery store. Customers enter randomly to check out, and then enter the shortest line. If the lines are equal, then the first available line is chosen. Each transaction takes a random amount of time to complete.

For additional work, expand the grocery line program to allow shoppers to:

  • Avoid a line if all lines are a certain length
  • Leave a line if they have waited beyond a certain time
  • Check if another line is shorter at specified time intervals
  • Switch lines if another line is shorter

Hint: The line only has to store wait times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment