Advertisement
binibiningtinamoran

LinkedStackReview

May 18th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class LinkedStackReview {
  4.  
  5.     public static void main(String []args) {
  6.         Random random = new Random();
  7.  
  8.         LinkedStack<Integer> ls1 = new LinkedStack<>();
  9.  
  10.         int value;
  11.         for (int i = 0; i <= 10; i++) {
  12.             value = 1 + random.nextInt(10);
  13.             ls1.push(value);
  14.         }
  15.         System.out.print("Original ls1 stack: ");
  16.         ls1.display();
  17.         System.out.println("No. of elements matching 8: " + ls1.numMatches(8));
  18.         ls1.display();
  19.         System.out.println();
  20.         LinkedStack<Integer> ls2 = new LinkedStack<>();
  21.         ls2.push(20); // bottom of the stack
  22.         ls2.push(1);
  23.         ls2.push(1);
  24.         ls2.push(1);
  25.         ls2.push(1);
  26.         ls2.push(1);
  27.         ls2.push(1);
  28.         ls2.push(192); // top of stack
  29.  
  30.         //System.out.println("No. of elements matching 20: " + numMatches(ls2,20));
  31.         //System.out.println("No. of elements matching 1: " + numMatches(ls2,1));
  32.         //System.out.println("ls2 stack display: ");
  33.         System.out.print("Original stack: ");
  34.         ls2.display();
  35.         System.out.println("No. of elements matching 1: " + ls2.numMatches(1));
  36.         System.out.println("No. of elements matching 20: " + ls2.numMatches(20));
  37.         ls2.display();
  38.  
  39.         LinkedStack<Integer> ls3 = new LinkedStack<>();
  40.         ls3.push(20); // bottom of the stack
  41.         System.out.println(ls2.isSingleton());
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement