
Stock Purchases Deque
October 2023
For this Java project, in order to learn more about data structures, I implemented a generic deque, using it to track stock purchases by adding new purchased stocks to the end and removing sold stocks from the front.
A deque is a double ended queue that can only directly access the front and back, whether to view, remove, or add elements. I used a linked list implementation, where each inner node references the next node in the deque
In order to iterate through the elements, you must use an Iterator that repeatedly accesses the next node, since indexing is not possible with a linked list. This is used for displaying the deque, because normally you wouldn’t access elements in the middle.


I created a UML class and object diagram in order to plan the structure of my code. After implementing the LinkedDeque, I wrote unit testing using JUnit to ensure it functioned correctly without causing errors. I then created a StockLedger package in order to demonstrate the LinkedDeque functionality by storing purchased stocks in the deque.
The StockLedger is an ArrayList of LedgerEntry, each of which contains a LinkedDeque of StockPurchases. All stocks of the same type go into the same LinkedDeque, which stores one node for every stock purchased.

The Main program buys and sells various stocks, displaying the ledger periodically to make the expected results easier to follow.

Thanks for checking out my project!
Back to Portfolio