In this lab, we'll work with the linked stack implementation, and add some extended operations intended mainly as an exercise with linked structures.
None of these methods should be implemented using the push and pop calls. Instead, implement them by directly manipulating the linked list structure. (As methods, they have access to private fields.)
Implement the indexed peek method. It takes an integer index which specifies which item to peek by giving the distance from the top item. (Calling it with zero is the same as regular peek.) If the index is out of bounds (too large or negative), it throws ElementNotFoundException.
Implement this by writing a loop that scans through the list until the correct item is found, and return it. If you reach the end, throw the exception.
Compile LinkedStack.java and fix any errors. Run the program ExtendedStackTest.java. You will have some errors, since you have not implemented all the methods. But the tester tests each of the extension methods in turn, and gives a message announcing the start of each test section, so you should be able to see the message announcing the testing of indexed peek, and that section should complete without errors. (The next message should be the one announcing the swaptop tests.) Fix any errors found for indexed peek.
Implement the swaptop method. This simply exchanges the top
two items, if they exist. If the stack is empty or has only one item, the
method does nothing. Implement it by rearranging the links in the
stack; do not try to use the pop or push methods in your
implementation.

Compile LinkedStack.java and fix any errors. Run the program ExtendedStackTest.java. The tester should complete the swaptop tests without detecting any errors.
Implement the pushother method. This takes a stack as argument, and pushes its content on the front, so that the order is not changed. The argument stack is emptied; its contents are added to the stack running the method.

Please note: The argument to pushother is declared ExtendedStackADT. You will need to cast it to LinkedStack before you can operate on it. The Java compiler may issue a warning for this cast. Unfortunately, Java doesn't have any way (that I could find) to declare in the StackADTExtended interface that the parameter needs to be implemented by the same class as the underlying object.
Compile LinkedStack.java and fix any errors. Run the program ExtendedStackTest.java. You should not see any error reports for the pushother test.