Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class LinkedStackReview {
- public static void main(String []args) {
- Random random = new Random();
- LinkedStack<Integer> ls1 = new LinkedStack<>();
- int value;
- for (int i = 0; i <= 10; i++) {
- value = 1 + random.nextInt(10);
- ls1.push(value);
- }
- System.out.print("Original ls1 stack: ");
- ls1.display();
- System.out.println("No. of elements matching 8: " + ls1.numMatches(8));
- ls1.display();
- System.out.println();
- LinkedStack<Integer> ls2 = new LinkedStack<>();
- ls2.push(20); // bottom of the stack
- ls2.push(1);
- ls2.push(1);
- ls2.push(1);
- ls2.push(1);
- ls2.push(1);
- ls2.push(1);
- ls2.push(192); // top of stack
- //System.out.println("No. of elements matching 20: " + numMatches(ls2,20));
- //System.out.println("No. of elements matching 1: " + numMatches(ls2,1));
- //System.out.println("ls2 stack display: ");
- System.out.print("Original stack: ");
- ls2.display();
- System.out.println("No. of elements matching 1: " + ls2.numMatches(1));
- System.out.println("No. of elements matching 20: " + ls2.numMatches(20));
- ls2.display();
- LinkedStack<Integer> ls3 = new LinkedStack<>();
- ls3.push(20); // bottom of the stack
- System.out.println(ls2.isSingleton());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement