Exemplo n.º 1
0
 @Test
 public void testSort() {
   Stack<Integer> s1 = new Stack<>();
   s1.push(3);
   s1.push(1);
   s1.push(5);
   s1.push(2);
   s1.push(8);
   s1.push(2);
   assertEquals("|315282", s1.toString());
   Stack.sort(s1);
   assertEquals("|853221", s1.toString());
 }
Exemplo n.º 2
0
  /** @param args the command line arguments */
  public static void main(String[] args) {

    Stack stack = new Stack(10);
    stack.push(1);
    stack.push(2);
    stack.push(3);
    stack.push(4);
    stack.push(5);

    System.out.println(stack.toString());

    while (!stack.isEmpty()) {
      int value = stack.pop();
      System.out.println(stack.toString());
      // System.out.println(value);
    }
  }
Exemplo n.º 3
0
  public static void main(String[] args) {

    // Create the stack object
    Stack s = new Stack();

    try {

      s.push(100);
      s.push(101);
      s.push(102);
      s.push(103);
      s.push(104);
      s.push(105);
      s.pop();
      s.pop();

      System.out.println(s.toString());
    } catch (Exception e) {
      System.out.println("Error: " + e);
    }
  }
Exemplo n.º 4
0
 @Test
 public void testTowersOfHanoi() {
   Stack<Integer> src = new Stack<>();
   Stack<Integer> temp = new Stack<>();
   Stack<Integer> dest = new Stack<>();
   for (int i = 5; i > 0; i--) {
     src.push(i);
   }
   System.out.println(src.toString());
   System.out.println(temp.toString());
   System.out.println(dest.toString());
   System.out.println();
   Stack.towersOfHanoi(5, src, temp, dest);
   System.out.println(src.toString());
   System.out.println(temp.toString());
   System.out.println(dest.toString());
   System.out.println();
   assertEquals("|54321", dest.toString());
 }