Question: Complete the implementation of the instance methods size() and swap() within the class LinkedStack below. The method size() returns the number of elements that are

Complete the implementation of the instance methods size() and swap() within the class LinkedStack below. The method size() returns the number of elements that are currently stored into this stack The method swap exchanges the first two elements (not the values): the first clement becomes the second and the second element becomes the first. The method returns false if there are less than 2 elements in the list. You cannot use the methods push and pop, instead the links of the structure (references) must be transformed. public class LinkedStack implements Stack { private class Elem {//Implements the nodes of the list private E info: private Elem next: private Elem(E info, Elem next) { this. info = info: this. next = next: } } private Elem top;//Instance variable, designates the top element public int size () {} public boolean swap() {} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
