Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🆕 🎓 Iterator Lab --- Create #876

Merged
merged 5 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/site/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Office Hours
labs/linked-structures/linked-structures
labs/queues/queues
labs/bags/sorted-bags
labs/iterators/iterators


.. toctree::
Expand Down
126 changes: 126 additions & 0 deletions src/site/labs/iterators/iterators.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
*********
Iterators
*********

* Feel free to use your laptop
* You are strongly encourage to work with others

* When you get stuck, ask those sitting around you for help
* Get used to working together in the labs
* Peer teaching and peer learning has been empirically shown to be very effective


Playing with Iterators
======================

The goal is to redefine stacks and queues such that the collections are iterable based on the details discussed in the
:doc:`Iterators Topic </topics/iterators/iterators>`.


Create an Array Iterator
------------------------

#. Create an ``ArrayIterator`` class that implements the ``Iterator`` interface


.. note::

Obviously one can simply download the :download:`ArrayIterator <../../../main/java/ArrayIterator.java>` code, but
this defeats the purpose of the lab. Instead, slowly and deliberately implement each method and take the time to
understand the details.



Create an Iterable Stack
------------------------

#. Download the :download:`Stack interface <../../../main/java/Stack.java>` and add it to the project
#. Modify the interface such that ``Stack`` extends ``Iterable``
#. Add the required ``iterator`` method to the interface

#. Download the :download:`ArrayStack <../../../main/java/ArrayStack.java>` class and add it to the project
#. Modify the ``ArrayStack`` such that it implements the ``iterator`` method

* Simply have it return the ``ArrayIterator``


#. Modify the existing ``toString`` method such that it uses an iterator

* Refer to the ``toString`` from the :download:`ArraySortedBag <../../../main/java/ArraySortedBag.java>` for help



Create an Iterable Queue
------------------------

#. Download the :download:`Queue interface <../../../main/java/Queue.java>` and add it to the project
#. Modify the interface such that ``Queue`` extends ``Iterable``
#. Add the required ``iterator`` method to the interface

#. Download the :download:`ArrayQueue <../../../main/java/ArrayQueue.java>` class and add it to the project
#. Modify the ``ArrayQueue`` such that it implements the ``iterator`` method
#. Modify the existing ``toString`` method such that it uses an iterator



Make the Linked Stack and Queue Iterable
----------------------------------------

Repeat the same ideas for the :download:`LinkedStack <../../../main/java/LinkedStack.java>` and
:download:`LinkedQueue <../../../main/java/LinkedQueue.java>`.


Improve ``equals``
------------------
Comment on lines +73 to +74
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pog


The current implementations of the ``Stack`` and ``Queue`` objects are only able to be equal to instances of the exact
same type. For example, it is currently only possible to have an ``ArrayStack`` be equal to another ``ArrayStack``.
However, this is less than ideal as it should be possible to check equality between ``Stack`` objects, regardless of
their specific implementation. In other words, it should be possible for an ``ArrayStack`` to be equal to a
``LinkedStack``.

Modify the existing ``equals`` methods within the various stack and queue implementations such that it is possible for
``Stack`` and ``Queue`` instances to be equal, regardless of their specific implementation.



Kattis Problems
===============

#. https://open.kattis.com/problems/quadrant
#. https://open.kattis.com/problems/judgingmoose
#. https://open.kattis.com/problems/timeloop
#. https://open.kattis.com/problems/oddities
#. https://open.kattis.com/problems/fizzbuzz
#. https://open.kattis.com/problems/twostones
#. https://open.kattis.com/problems/spavanac
#. https://open.kattis.com/problems/cetvrta
#. https://open.kattis.com/problems/bus
#. https://open.kattis.com/problems/timeloop
#. https://open.kattis.com/problems/oddities
#. https://open.kattis.com/problems/fizzbuzz
#. https://open.kattis.com/problems/sibice
#. https://open.kattis.com/problems/datum
#. https://open.kattis.com/problems/dicecup
#. https://open.kattis.com/problems/autori
#. https://open.kattis.com/problems/apaxiaaans
#. https://open.kattis.com/problems/hissingmicrophone
#. https://open.kattis.com/problems/trik
#. https://open.kattis.com/problems/pot
#. https://open.kattis.com/problems/filip
#. https://open.kattis.com/problems/reversebinary
#. https://open.kattis.com/problems/sevenwonders
#. https://open.kattis.com/problems/zamka
#. https://open.kattis.com/problems/bijele
#. https://open.kattis.com/problems/cold
#. https://open.kattis.com/problems/nastyhacks
#. https://open.kattis.com/problems/grassseed
#. https://open.kattis.com/problems/pet
#. https://open.kattis.com/problems/batterup
#. https://open.kattis.com/problems/aboveaverage
#. https://open.kattis.com/problems/icpcawards
#. https://open.kattis.com/problems/quickbrownfox
#. https://open.kattis.com/problems/nodup
#. https://open.kattis.com/problems/conundrum
#. https://open.kattis.com/problems/bela
#. https://open.kattis.com/problems/kornislav