//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 6.9 on page 120
//  Testing a reversed(Stack) method

import java.util.Stack;

public class Pr0609
{ public static void main(String[] args)
  { Stack kids = new Stack();
    kids.push("Sara");
    kids.push("John");
    kids.push("Andy");
    kids.push("Mike");
    System.out.println(kids);
    System.out.println(reversed(kids));
  }
  
  private static Stack reversed(Stack stack)
  { Stack tempStack = new Stack();
    Stack newStack = new Stack();
    while(!stack.empty())
    { Object x = stack.pop();
      tempStack.push(x);
      newStack.push(x);
    }
    while(!tempStack.empty())
      stack.push(tempStack.pop());
    return newStack;
  }
}
  