Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package linkedlist;
- public class MainApp {
- public static void main(String[] args) {
- String e1 = new String("a");
- String e2 = new String("m");
- String e3 = new String("g");
- String e4 = new String("d");
- String e5 = new String("j");
- // ----------------SINGLE LIST--------------------------
- SortedLinkedList list = new SortedLinkedList();
- list.addElement(e1); // gives null pointer exception
- list.addElement(e2);
- list.addElement(e3);
- list.addElement(e4);
- list.addElement(e5);
- System.out.println("number in the list via count method: " + list.countElements());
- System.out.println("number in the list via countRecursive method: " + list.countElementsRecursive());
- list.removeLast();
- list.udskrivElements();
- System.out.println(
- "an element has been removed via removeLast, should now give one less: " + list.countElements());
- list.removeElement(e3);
- System.out.println("should print e1: " + e1.toString());
- System.out.println("should print e2: " + e2.toString());
- System.out.println("should print e3: " + e3.toString());
- System.out.println("should print e4: " + e4.toString());
- System.out.println("should print e5: " + e5.toString());
- System.out.println(
- "an element has been removed via removeElement, should now give one less: " + list.countElements());
- // ----------------DOUBLE LIST-----------------------
- SortedLinkedListDouble listDouble = new SortedLinkedListDouble();
- listDouble.addElement(e1);
- listDouble.addElement(e2);
- listDouble.addElement(e3);
- listDouble.addElement(e4);
- listDouble.addElement(e5);
- System.out.println("number in the list via count method: " + listDouble.countElements());
- listDouble.removeLast(); // returns null
- listDouble.udskrivElements(); // returns null
- System.out.println(
- "an element has been removed via removeLast, should now give one less: " + listDouble.countElements());
- listDouble.removeElement(e3); // gives null pointer exception
- System.out.println("should print e2: " + e2.toString());
- System.out.println("an element has been removed via removeElement, should now give one less: "
- + listDouble.countElements());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement