Skip to content

Commit

Permalink
README.md: Clarify expectations for LinkedDeque process
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlin1 committed Sep 28, 2022
1 parent 966f8c7 commit 15b87f3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ A `LinkedDeque` should always maintain the following invariants before and after
- The sentinel nodes `front.prev` and `back.next` always reference null. If `size` is at least 1, `front.next` and `back.prev` reference the first and last regular nodes.
- The nodes in your deque have consistent `next` and `prev` fields. If a node `curr` has a `curr.next`, we expect `curr.next.prev == curr`.

> ✨ Write down what your `LinkedDeque` will look like on paper before writing code! The number of pictures drawn often correlates with the successfulness of an implementation. Better yet, if you can find a willing partner, have them give some instructions while you attempt to draw everything out. Be sure to think carefully about what happens if the data structure starts empty, some items are added, all the items are removed, and then some items are added again.
> ✨ Write down what your `LinkedDeque` will look like on paper before writing code! Drawing more pictures often leads to more successful implementations. Better yet, if you can find a willing partner, have them give some instructions while you attempt to draw everything out. Be sure to think carefully about what happens if the data structure starts empty, some items are added, all the items are removed, and then some items are added again.
To assist in debugging, we've provided a `checkInvariants` method that returns null if and only if the above invariants are maintained (at the time the method is called), or a string describing the problem. One way to use this method is to add debugging print statements where you *hypothesize* a bug might be present. But it can be tedious editing code, moving the line around, and then running it again just to call `checkInvariants` at a different place. A better way is by [Using **Evaluate Expression** and **Watches** with IntelliJ](https://youtu.be/u5NSgMCkqOg). This allows you to pause the program at any point in time and call `checkInvariants()` or even visualize the `LinkedDeque` using the [jGRASP](https://plugins.jetbrains.com/plugin/12769-jgrasp) or [Java Visualizer](https://plugins.jetbrains.com/plugin/11512-java-visualizer) plugins.

Lastly, if your first try goes badly, don't be afraid to scrap your code and start over. My solution adds only about 50 lines of code to `LinkedDeque.java`.
Lastly, if your first try goes badly, don't be afraid to scrap your code and start over. My solution adds between 4 to 6 lines of code per method.

### ArrayListDeque

Expand Down

0 comments on commit 15b87f3

Please sign in to comment.