Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Stacks, Queues and Linked Stacks, computer science homework help

For the next problems write a client to test the following methods. Check out the lecture notes(attached) for thenecessary files(StackADT.java, LinkedStackClass.java, QueueADT.java, QueueClass.java,QueueException.java, QueueOverflowException.java, andQueueUnderflowException.java.) 

1. (Method: printBackStack) Task: Display the contents of a stack in reverse order (top to bottom),leaving the stack unchanged.

SOLUTION:

public static void printBackStack(LinkedStackClass<Integer> intStack) { ...

}2. (Method: printStack) Task: Display the contents of a stack in direct order (bottom to top), leaving

the stack unchanged.

SOLUTION:

public static void printStack(LinkedStackClass<Integer> intStack) { ...

}3. (Method: getSecond) Task: Find the second item in a stack, leaving the stack unchanged.

SOLUTION:

public static Integer getSecond(LinkedStackClass<Integer> intStack) { ...

}

4. (Method: countItems) Task: Count the number of items in a stack, leaving the stack unchanged.SOLUTION:

public static int countItems(LinkedStackClass<Integer> intStack) { ...

}5. (Method: removeItem) Task: Delete every occurrence of a specified item from a stack, leaving the

order of the remaining items unchanged.

SOLUTION:

public static void removeItem(LinkedStackClass<Integer> intStack, Integer n) { ...

}

6. (Method: reverseStack) Task: Reverse a stack, using a queue. The original stack is lost.SOLUTION:

public static void reverseStack(LinkedStackClass<Integer> s) { QueueClass<Integer> q = new QueueClass<Integer>(); ...

}7. (Method: reverseQueue) Task: Reverse a queue, using a stack. The original queue is lost.

SOLUTION:

public static void reverseQueue(QueueClass<Integer> q){ LinkedStackClass<Integer> s = new LinkedStackClass<Integer>(); ...

}8. (Method: printQueue) Task: Display the contents of a queue in direct order, leaving the queue

unchanged.

SOLUTION:

public static void printQueue(QueueClass<Integer> q) { ...

}

SAMPLE OUTPUT:

Enter integers (999 to stop): 25 10 15 10 20 37 10 59 21 10 27 20 4 2 10 53 47 37 5977 27 20 10 999The original stack printed in direct order (bottom to top) is:25 10 15 10 20 37 10 59 21 10 27 20 4 2 10 53 47 37 59 77 27 20 10The stack printed in reverse order (top to bottom) is:10 20 27 77 59 37 47 53 10 2 4 20 27 10 21 59 10 37 20 10 15 10 25The stack stores 23 items.The top is: 10The second item (below top) is: 20Enter value to be removed from stack: 10The stack after removing every occurrence of 10 is:25 15 20 37 59 21 27 20 4 2 53 47 37 59 77 27 20Reversed the stack. The new stack printed in direct order is:20 27 77 59 37 47 53 2 4 20 27 21 59 37 20 15 25The queue is:3 6 9 12 15 18 21 24 27 30The reversed queue is:30 27 24 21 18 15 12 9 6 3
Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question