//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 6.10 on page 120
//  Testing a penultimate(Stack) method

import java.util.Stack;

public class Pr0610
{ 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(penultimate(kids));
  }
  
  private static Object penultimate(Stack stack)
  { Object x1 = stack.pop();
    Object x2 = stack.pop();
    stack.push(x2);
    stack.push(x1);
    return x2;
  }
}
  