X1667: Use a stack to a reverse order of a clump

Description

Write a method void reverseClump(Clump<String> clump) that takes a Clump as argument and uses a stack to reverse the order of the elements in the Clump.

A Clump is a non-descript linear data structure that operates as a FIFO. It has a put() method that adds elements to one end of the clump, and a get() method that removes and returns an element from the other end of the clump. These two methods implement a first-in first-out policy. It also has a size() method the returns the number of elements stored in the clump.

Constraints

  • You must use a Stack<T> to reverse the elements.
  • You can allocate a stack by calling the constructor as new Stack<String>().
  • The method reverseClump() modifies the clump resulting with the same values in reverse order.
  • Do not create a new Clump object, just reuse the same one.
  • The argument clump is never null, but might be empty.

Reference

For reference, a Clump is defined as shown below.

public class Clump<E> {
   public void put(E v) {...}
   public E get() {...}
   public int size() {...}
}

For reference, a Stack is defined as shown below.

public class Stack<T> {
   public boolean push(T it) {...}
   public T pop() {...}
   public T peek() {...}
   public int size() {...}
   public boolean isEmpty() {...}
}

Your Answer:

Feedback

Your feedback will appear here when you check your answer.