CSE 212: Programming with Data Structures

Team Activity: Practice Stacks and Queues

For this activity, you need to meet with your group for a synchronous meeting using a video sharing tool, such as Microsoft Teams.

This activity is designed to take about one hour.

Instructions

Use the following as an agenda for your team meeting. The person that is assigned to be the Lead Student for this gathering should help guide the group through these steps.

Before the meeting: Verify the time, location, and lead student

This could be as simple as posting a message to your Microsoft Teams channel that says something like, "Hi guys, are we still planning to meet tomorrow at 7pm Mountain Time? Let's use the Microsoft Teams video feature again." Or, if someone else has already posted a message like this, it could be as simple as "liking" their message.

Make sure to identify who will be the lead student for this week. For example, "Emily, are you still planning to be the lead student for this week?"

Begin with Prayer

Review the Preparation Learning Activities (5 minutes)

Briefly discuss the following questions: (The Lead Student should ask each question.)

  1. What is the difference between a Stack and a Queue?
  2. What is one example where a stack may be helpful?
  3. What is one example where a queue may be helpful?
  4. When might someone need to review code without running it?

Review a Complex Stack Example (20 minutes)

For some teams, this part of the activity may take a long time to finish completely. You should work together on the activity for the time indicated. At the end of this time, if you are still working on it, the Lead Student should direct the group to stop working and review the sample solution for this step, so that you have time to move on to the next step.
  1. In VS Code, browse to the week02/teach project in the course repository, and open the ComplexStack.cs file. (Note: You should not execute this code yet. After you complete these practice problems, you are welcome to execute the code.)
  2. The code does "something." Read through the code and form a hypothesis of what it does. You should write down your thoughts before you proceed to the next step.
  3. Test your hypothesis by "running" the following three tests. You should not run the C# code on your computer. Instead, you should use paper and pencil to desk check the code using the inputs provided below.

    Identify where in the code a value of true or false will be returned for each of these three example inputs. If a false is returned, what is the contents of the stack when the failure was detected?

    After you have finished, compare your answer to the provided solution.

    1. Input: (a == 3 or (b == 5 and c == 6))
      Solution

      This class is using a stack to check if the input string has balanced braces in it.

      The result of this test is:

      True: The stack was empty at the end.

    2. Input: (students]i].Grade > 80 and students[i].Grade < 90)
      Solution False: This string has the wrong opening square bracket so it fails when popping the ] character and checking to see if the stack as a [ on top.
    3. Input:(robot[id + 1].Execute(.Pass() || (!robot[id * (2 + i)].Alive && stormy) || (robot[id - 1].Alive && lavaFlowing))
      Solution False: This one is missing a final ) character at the end. Thus, the stack was not empty when it was supposed to be.

Testing a Customer Service Queue (35 minutes)

  1. In VS Code, browse to the week02/teach project in the course repository, and open the CustomerService.cs file.
  2. The CustomerService class maintains a queue of records that include the name, account ID, and the problem. Here are the detailed requirements (which can not be changed):
    1. The user shall specify the maximum size of the Customer Service Queue when it is created. If the size is invalid (less than or equal to 0) then the size shall default to 10.
    2. The AddNewCustomer method shall enqueue a new customer into the queue.
    3. If the queue is full when trying to add a customer, then an error message will be displayed.
    4. The ServeCustomer function shall dequeue the next customer from the queue and display the details.
    5. If the queue is empty when trying to serve a customer, then an error message will be displayed.
  3. Write test cases based on the requirements above and then implement the tests. Ensure that your tests cover all of the requirements listed above.
  4. Run your test cases. If the test case fails, then look in the related code for the errors and fix them. All your test cases should pass when the code is fixed. There are three major errors in the code you were given.
  5. When you are done, uncomment the lines in Program.cs to include running the CustomerServiceSolution and take a look at the CustomerServiceSolution.cs file and discuss it together.
Once again, be conscious of the time you are spending. If you have reached the end of your time for this part of the activity, the Lead Student should help the team conclude and review the sample solution.

Conclude

At the end of your meeting:

  1. Determine who will be the lead student for the next meeting.

Submission

When you are finished:

Other Links: