Advertisement
Guest User

Untitled

a guest
Oct 31st, 2019
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. /**
  8. *
  9. * @author bdb52
  10. */
  11. public class DequeDriver {
  12. public static void main(String [] args){
  13. System.out.println("If it doesn't work i'll cry.");
  14. System.out.println();
  15. ArrayDeque <Integer> s = new ArrayDeque<>();
  16. s.addFirst(-1);
  17. s.addFirst(2);
  18. s.addFirst(3);
  19. s.addLast(4);
  20. s.addFirst(5);
  21. // System.out.println("Checkin' da size: " + s.size());
  22. System.out.println("Checking the contents of this bad boi (should be 5, 3, 2, -1, 4: ");
  23. for (Object i : s.toArray())
  24. System.out.print(i + " ");
  25. System.out.println();
  26. System.out.println("Whats first?(should be a 5): " + s.getFirst());
  27. System.out.println("Whats last? (should be a 4): " + s.getLast());
  28. System.out.println("Modifying Deque using offer...");
  29. System.out.println("Adding 55 to the front of the Deque using offerFirst: " + s.offerFirst(55));
  30. System.out.println("Whats the new first? (using peek, should be a 55): " + s.peekFirst());
  31. System.out.println("Adding 77 to the tail of the Deque using offerLast: " + s.offerLast(77));
  32. System.out.println("Whats last? (using peek, should be a 77): " + s.peekLast());
  33. //System.out.println("Removing the head: " + s.pollFirst());
  34. System.out.println("Checking if this bad boi contains a 3 (should be true): " + s.contains(3));
  35. System.out.println("Checking if this bad boi contains a 1 (should be a hard false): " + s.contains(1));
  36. System.out.println("Testing pollFirst: " + s.removeFirst());
  37. System.out.println("Testing pollLast: " + s.removeLast());
  38. System.out.println("Checking the contents of this bad boi (should be 5, 3, 2, -1, 4: ");
  39. for (Object i : s.toArray())
  40. System.out.print(i + " ");
  41. System.out.println();
  42. System.out.println("Testing the isEmpty method(should be false): " + s.isEmpty());
  43. System.out.println("Clearing the Deque...");
  44. s.clear();
  45. System.out.println("Checking to see if it worked(size should be 0): " + s.size());
  46. System.out.println("Double Checking by isEmpty(should be true): " + s.isEmpty());
  47. // System.out.println("Checking the contents of this bad boi (should be -1, 3, 5, 10): ");
  48. // for (Object i : s.toArray())
  49. // System.out.print(i + " ");
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement