From 34b3909856be9ef0aa85935840ef5443b7bf18d4 Mon Sep 17 00:00:00 2001 From: stephey Date: Tue, 29 Mar 2011 06:52:04 +0000 Subject: [PATCH] Changed LinkedList to return a boolean instead of crashing when an object isn't found in the remove method. --- Robust/src/ClassLibrary/LinkedList.java | 32 +++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Robust/src/ClassLibrary/LinkedList.java b/Robust/src/ClassLibrary/LinkedList.java index e2af0104..3fe96141 100644 --- a/Robust/src/ClassLibrary/LinkedList.java +++ b/Robust/src/ClassLibrary/LinkedList.java @@ -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() { -- 2.34.1