Question: This needs to be in eclipse IDE and in Java only. Implement a method transfer in class LinkedStack. This method should transfer all elements of
This needs to be in eclipse IDE and in Java only.
Implement a method transfer in class LinkedStack. This method should transfer all elements of a stack sourceS to another stack targetS so that the element that starts at the top of sourceS is the first one to be inserted in targetS, and the element at the bottom of sourceS ends up at the top of targetS. The operation should result in sourceS being an empty stack. Test this method in the main method of LinkedStack
CODE:
public class LinkedStack implements Stack
The primary storage for elements of the stack
private SinglyLinkedList list new SinglyLinkedList; an empty list
new SinglyLinkedList cane be replaced by new SinglyLinkedList
Constructs an initially empty stack.
public LinkedStack new stack relies on the initially empty list
Returns the number of elements in the stack.
@return number of elements in the stack
@Override
public int size return list.size;
Tests whether the stack is empty.
@return true if the stack is empty, false otherwise
@Override
public boolean isEmpty return list.isEmpty;
Inserts an element at the top of the stack.
@param element the element to be inserted
@Override
public void pushE element list.addFirstelement;
Returns, but does not remove, the element at the top of the stack.
@return top element in the stack or null if empty
@Override
public E top return list.first;
Removes and returns the top element from the stack.
@return element removed or null if empty
@Override
public E pop return list.removeFirst;
Produces a string representation of the contents of the stack.
ordered from top to bottom
This exists for debugging purposes only.
@return textual representation of the stack
public String toString
return list.toString;
main method
public static void mainString args
throws CloneNotSupportedException
LinkedStack ls Thit new LinkedStack;
lspushApple;
lspushKiwi;
lspushLime;
System.out.println lstoString;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
