Lab GitHub Repo: Stacks and Queues
In this lab, you’ll apply stacks and queues to solve two real-world challenges. First, you’ll implement a parentheses validator using a stack—a feature commonly used in compilers or formatting tools. Then, you'll simulate a customer raffle system using a queue, where entries are processed in the order received and a winner is selected.
By focusing on LIFO (last-in, first-out) and FIFO (first-in, first-out) behavior, you’ll develop a stronger understanding of foundational data structures used in systems like parsers, schedulers, and task processors.
- Implement a function that validates balanced parentheses using a stack.
- Create a queue that stores customer entries and:
- Selects a random winner.
- Dequeues up to and including the winner.
- Display the result of both operations clearly in your output.
The Challenge: Demonstrate your understanding of stack and queue behavior in common technical workflows.
- File:
custom_stack.py
- Function:
is_valid_parentheses(s: str) -> bool
- Returns
True
if the parentheses in the string are balanced.
- File:
custom_queue.py
- Class:
Queue
- Methods:
enqueue(item)
dequeue()
peek()
is_empty()
select_and_announce_winner()
→ Randomly selects a winner and dequeues everyone up to and including that customer.
- Go to the provided GitHub repository link.
- Fork the repository to your GitHub account.
- Clone the forked repository to your local machine.
- Open the project in your Python-friendly IDE (VSCode, PyCharm, etc.).
-
Starter code uses
pass
:- You’ll see
pass
in method bodies—this is a Python placeholder. - Replace it with your actual code to make each method work.
- You’ll see
-
Build each file:
- Implement
Queue
methods as described above. - Write the stack validator function for balanced parentheses.
- Implement
-
Run Tests:
- Execute the provided test file with:
python test_structures.py
- Ensure all tests pass before submission.
- Execute the provided test file with:
-
Push and Merge:
- Commit your work regularly.
- Push to your feature branch.
- Open a Pull Request (PR).
- Merge to
main
after review.
- Comment your logic: Especially around recursive or loop-based behavior.
- Explain your thinking in your function definitions.
- README: Make sure your repo’s README includes how to run the project.
- Clean Up:
- Remove debug prints.
- Ensure your
.gitignore
ignores.pyc
,__pycache__
, etc.
Once your lab is complete and all tests are passing:
- Push your code to GitHub.
- Submit the link to your repo through Canvas using CodeGrade.