Advertisement
Guest User

Linked List Tester

a guest
Apr 27th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. public class Program {
  2.  
  3.     public static void main(String[] args) {
  4.         LinkedList l = new LinkedList();
  5.         System.out.println(l.size() == 0 ? ":) New lists are of size 0" : ":( New lists should be size 0");
  6.         l.print(); l.delete(5);
  7.         System.out.println(l.contains(-1) ? ":( New lists should not contain -1" : ":) New lists are searchable, returning false.");
  8.         System.out.println(l.isEmpty() ? ":) isEmpty is true for new lists." : ":( isEmpty should return true for new lists.");
  9.         l = new LinkedList(); l.insert(3); l.insert(4); l.insert(5);
  10.         System.out.println(l.size() == 3 ? ":) List of size 3 returns 3 for size" : ":( List of size 3 should return 3 for size");
  11.         l.delete(3);
  12.         System.out.println(l.size() == 2 && l.contains(4) && l.contains(5) && !l.contains(3) ? ":) Deleting 3 from {3, 4, 5} works" : ":( Deleting 3 from {3, 4, 5} doesn't work");
  13.         l = new LinkedList(); l.insert(3); l.insert(4); l.insert(5); l.delete(4);
  14.         System.out.println(l.size() == 2 && l.contains(5) && l.contains(3) && !l.contains(4) ? ":) Deleting 4 from {3, 4, 5} works" : ":( Deleting 4 from {3, 4, 5} doesn't work");
  15.         l = new LinkedList(); l.insert(3); l.insert(4); l.insert(5); l.delete(5);
  16.         System.out.println(l.size() == 2 && l.contains(4) && l.contains(3) && !l.contains(5) ? ":) Deleting 5 from {3, 4, 5} works" : ":( Deleting 5 from {3, 4, 5} doesn't work");
  17.         l = new LinkedList(); l.insert(3); l.insert(5); l.insert(9); l.insert(7); l.delete(9); l.insert(9);
  18.         System.out.println("Should print a list of 3, 5, 7 & 9.  You check:");
  19.         l.print();
  20.        
  21.         System.out.println("Thanks for using the LinkedList tester.");
  22.     }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement