Advertisement
LoganBlackisle

mainapp

Jul 31st, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. package linkedlist;
  2.  
  3. public class MainApp {
  4.  
  5.     public static void main(String[] args) {
  6.         String e1 = new String("a");
  7.         String e2 = new String("m");
  8.         String e3 = new String("g");
  9.         String e4 = new String("d");
  10.         String e5 = new String("j");
  11.  
  12.         // ----------------SINGLE LIST--------------------------
  13.         SortedLinkedList list = new SortedLinkedList();
  14.  
  15.         list.addElement(e1); // gives null pointer exception
  16.         list.addElement(e2);
  17.         list.addElement(e3);
  18.         list.addElement(e4);
  19.         list.addElement(e5);
  20.  
  21.         System.out.println("number in the list via count method: " + list.countElements());
  22.         System.out.println("number in the list via countRecursive method: " + list.countElementsRecursive());
  23.  
  24.         list.removeLast();
  25.         list.udskrivElements();
  26.  
  27.         System.out.println(
  28.                 "an element has been removed via removeLast, should now give one less: " + list.countElements());
  29.  
  30.         list.removeElement(e3);
  31.  
  32.         System.out.println("should print e1: " + e1.toString());
  33.         System.out.println("should print e2: " + e2.toString());
  34.         System.out.println("should print e3: " + e3.toString());
  35.         System.out.println("should print e4: " + e4.toString());
  36.         System.out.println("should print e5: " + e5.toString());
  37.         System.out.println(
  38.                 "an element has been removed via removeElement, should now give one less: " + list.countElements());
  39.  
  40.         // ----------------DOUBLE LIST-----------------------
  41.  
  42.         SortedLinkedListDouble listDouble = new SortedLinkedListDouble();
  43.  
  44.         listDouble.addElement(e1);
  45.         listDouble.addElement(e2);
  46.         listDouble.addElement(e3);
  47.         listDouble.addElement(e4);
  48.         listDouble.addElement(e5);
  49.  
  50.         System.out.println("number in the list via count method: " + listDouble.countElements());
  51.  
  52.         listDouble.removeLast(); // returns null
  53.         listDouble.udskrivElements(); // returns null
  54.  
  55.         System.out.println(
  56.                 "an element has been removed via removeLast, should now give one less: " + listDouble.countElements());
  57.  
  58.         listDouble.removeElement(e3); // gives null pointer exception
  59.  
  60.         System.out.println("should print e2: " + e2.toString());
  61.  
  62.         System.out.println("an element has been removed via removeElement, should now give one less: "
  63.                 + listDouble.countElements());
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement