Describe the major difference between a stack and a queue -


Data Structure and Algorithm

Question 1:

Stacks and queues are two ways to store data in a linear fashion.

a. Describe the major difference between a stack and a queue.

b. The picture below is of a coffee cup dispenser. Is it a stack or a queue? Explain. (Hint : LIFO or FIFO)

Question 2:

Using the stack algorithm for computing Post fix expressions, trace the algorithm on the Post fix expression below, showing the stack at the end of each iteration of the loop. (As given on Slide#29 & #30)

(Draw a separate picture of the stack each time, so we can see the overall process of the algorithm.)

Question 3:

You have already created Java project name Algorithm within same project create package name npu.dataStructure.stack and write a class name TheStack with following methods implimantation.

//constructor
public TheStack(int stackSize){ //your code here}

public void push(Object obj){ //your code here } public Object pop(){//your code here }
public Object peek(){//your code here } public boolean isEmpty(){//your code here } private boolean isFull(){//your code here }

public void displayStack(){//your code here }

create another class which will have main method to test TheStack class. Push some Strings in the stackand display the stack. pop all strings out of the stack. Display stack - it should give you message that stack is currently empty. Pop one more extra string from stack - it should give you message indicating that you are trying to pop String out of stack when its empty.

Question 4:

You have already created Java project name Algorithm within same project create package name npu.dataStructure.queue and write a class name TheQueue with following methods implementation.

//constructor
public TheQueue(int capacity){//your code here}

public void insert(Object value){ //your code here}} public void remove(){//your code here}
public void peek(){//your code here}
public int size(){//your code here} //displays current elements in the queue

public boolean isEmpty(){//your code here} public boolean isFull(){//your code here }
public static void displayTheQueue(){ //your code here}

Solution Preview :

Prepared by a verified Expert
Computer Engineering: Describe the major difference between a stack and a queue -
Reference No:- TGS01527578

Now Priced at $40 (50% Discount)

Recommended (96%)

Rated (4.8/5)