Question: Here is ArrayStack: public class ArrayStack implements Stack { private int capacity; private int top; private T[ ] stack; @SuppressWarnings(unchecked) public ArrayStack ( ) {

Here is ArrayStack:
public class ArrayStack implements Stack {
private int capacity; private int top; private T[ ] stack; @SuppressWarnings("unchecked") public ArrayStack ( ) { capacity = 10; top = 0; stack = (T [ ]) new Object [capacity]; } @SuppressWarnings("unchecked") public ArrayStack (int cap) { capacity = cap; top = 0; stack = (T [ ]) (new Object [capacity]); } public void push (T element) { if (top == capacity) resize(); stack[top] = element; top++; } @SuppressWarnings("unchecked") private void resize() { T [ ] temp = (T[ ]) new Object [capacity*2]; for (int k = 0; k
}
Here is LinkedStack:
public class LinkedStack implements Stack {
private LinearNode top; private int count; public LinkedStack ( ) { // POST: empty stack top = null; count = 0; } public void push (T element) { // POST: add element to top of stack LinearNode temp = new LinearNode (element); temp.setNext(top); top = temp; count++; } public T pop ( ) throws EmptyCollectionException // PRE: stack is not empty // POST: remove and return top element { if (isEmpty()) throw new EmptyCollectionException ( ); T result = top.getElement(); top = top.getNext(); count--; return result; } public T peek ( ) throws EmptyCollectionException // PRE: stack is not empty // POST: return top element { if (isEmpty()) throw new EmptyCollectionException ( ); return top.getElement(); } public boolean isEmpty() // POST: return true if stack is empty, else false { return count==0; }
public int size() { // POST: return number of elements in stack return count; } }
Here is LinkedQueue:
public class LinkedQueue implements Queue { private LinearNode head, tail; private int count; public LinkedQueue ( ) { count = 0; head = tail = null; } public void enqueue (T element) { LinearNode node = new LinearNode (element); if (isEmpty()) head = node; else tail.setNext(node); tail = node; count++; } public T dequeue () throws EmptyCollectionException { if (isEmpty()) throw new EmptyCollectionException (); T result = head.getElement(); head = head.getNext(); count--; if (isEmpty()) tail = null; return result; } public T getFront ( ) throws EmptyCollectionException { if (isEmpty()) throw new EmptyCollectionException (); T result = head.getElement(); return result; } public boolean isEmpty () { return count == 0; } public int size () { return count; } }
2. (6) Using the ArrayStack class developed in lecture, list the output of each line ArrayStack s = new ArrayStack:Integer> ( ); s.push (20); s.push (40);s.push (50); System.out.println (s.size()); System.out.println (s.peek()); s.push (80); s.push (30);s.pop ); s.push (10); while (!s.empty()) { Systemout.print (s.peek ()+ " "); s.pop ); 3. (4) Using the LinkedStack code, draw a picture of the linked list below after a pop() method. Draw the nodes and values in the next field (arrow or null). Reference top should use an arrow to point to its node. If a node has been garbage-collected, do not include it in the picture top 15 25 10 null Your picture top: 4. (4) Using the ArrayQueue code and the original state shown below, draw a picture of the array after an enqueue of value 5. Show items in the queue and indicate the value in front and rear 25 10 30 0 4 rear: 4 front: 1 Your picture 4 front: rear