Changed LinkedList to return a boolean instead of crashing when an object isn't found...
authorstephey <stephey>
Tue, 29 Mar 2011 06:52:04 +0000 (06:52 +0000)
committerstephey <stephey>
Tue, 29 Mar 2011 06:52:04 +0000 (06:52 +0000)
Robust/src/ClassLibrary/LinkedList.java

index e2af01042c825712d82977ade321414459fa0d8f..3fe961411fcea0d9c839cd9dfadb70b04a441a7d 100644 (file)
@@ -151,27 +151,29 @@ public class LinkedList {
     return o;
   }
 
-  public void remove(Object o) {
+  public boolean remove(Object o) {
     if( head == null ) {
-      System.out.println("LinkedList: illegal remove( Object o )");
-      System.exit(-1);
+//      System.out.println("LinkedList: illegal remove( Object o )");
+//      System.exit(-1);
+      return false;
     }
     LinkedListElement e = head;
-    while( e != null ) {
-      if( e.element == o ) {
-       if( e.prev != null ) {
-         e.prev.next = e.next;
-       }
-       if( e.next != null ) {
-         e.next.prev = e.prev;
-       }
-       size--;
-       return;
+    while (e != null) {
+      if (e.element == o) {
+        if (e.prev != null) {
+          e.prev.next = e.next;
+        }
+        if (e.next != null) {
+          e.next.prev = e.prev;
+        }
+        size--;
+        return true;
       }
       e = e.next;
     }
-    System.out.println("LinkedList: illegal remove( Object o ), "+o+" not found");
-    System.exit(-1);
+//    System.out.println("LinkedList: illegal remove( Object o ), "+o+" not found");
+//    System.exit(-1);
+    return false;
   }
 
   public Object pop() {