Stacks and Queues in Java

The stack and the queue is defined by two basic operations: insert a new item, and remove an item.



Representing stacks and queues with arrays is a natural idea. The rule used for a queue is to always remove the item that has been in the collection the most amount of time. This policy is known as first-in-first-out or FIFO. The rule used for a stack is to always remove the item that has been in the collection the least amount of time. This policy is known as last-in first-out or LIFO.

In stacking, we name the stack insert method push() and the stack remove operation pop(). When we queue, we name the insert method enqueue() and the remove dequeue().

Here's an exercise we just did in school today though it's quite complicated, i just wanna share the codes. It's about push(inserting) and pop(deleting) for the stack; as well as enqueue(inserting) and dequeue(deleting). Download the codes below:







It's important to download all three files.

No comments:

Post a Comment

Extended Search

Custom Search
Hello World