Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A stack is a LIFO data structure (last in, first out). Like trays in a cafeteria...you always grab the one at the top which was

A stack is a LIFO data structure (last in, first out). Like trays in a cafeteria...you always grab the one at the top which was most recently placed on the stack. A queue is a FIFO data structure (first in, first out). Like waiting in line for Financial Aid...you always take the student who was waiting the longest. We can implement a Queue and a Stack using LinkedLists Instructions: 1. Create a class called MyQueue which has one instance variable -- a LinkedList of Strings. Initialize it to an empty LinkedList (why?) 2. Create a method push(String s) which will push the passed string to the appropriate place in the queue (where is that). Look at the API methods for LinkedList. Which are the most helpful? 3. Create a method pop() which will do two things: a. Remove the appropriate string from the list (which one is this?) b. Return that string as the return value of the method. 4. Create a method isEmpty() that returns true if the Queue is Empty and false otherwise 5. Create a class called MyStack which also has one instance variable -- a Linked List of Strings 6. Create methods push(String s) , pop() , and isEmpty() which function as above...but they should work the way stacks work, not queues 7. Create a Driver (called myTestDriver) to test using your new MyStack and MyQueue classes. 8. What things do you need to take into account when popping?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions