src/textgen/MyLinkedList.java
/** Remove a node at the specified index and return its data element.
	 * @param index The index of the element to remove
	 * @return The data element removed
	 * @throws IndexOutOfBoundsException If index is outside the bounds of the list
	 * 
	 */
Remove a node at the specified index and return its data element.
@param index The index of the element to remove
@return The data element removed
@throws IndexOutOfBoundsException If index is outside the bounds of the list
Remove a node at the specified index and return its data element . @param index The index of the element to remove @return The data element removed @throws IndexOutOfBoundsException If index is outside the bounds of the list
public E remove(int index) {
		/*
		 * Algorithm:
		 * Check if the index is not out of bound: (for an empty list) : throw IndexOutOfBoundException
		 * index<0 || index>=size throw IndexOutOfBoundException
		 * initialize currentNode:head
		 * Initialize counter i to iterate the list from the start to index : i=0
		 * for each iteration check:
		 * currentNode=currentNode.next;
		 * 
		 */
		LLNode<E> currentNode=null;
		if(index<0 || (index>=0 && index>=size)){
			throw new IndexOutOfBoundsException();
		}else {
			currentNode=head;
			for(int i=0;i<=index;i++){
				currentNode=currentNode.next;
			}
			if (size()==1){
				head.next=currentNode.next;
				tail.prev=currentNode.prev;				
			} else {
				System.out.println(" #$%$ size="+size());
				System.out.println(" currentNode ="+currentNode +  " @$#@#$@ "+ currentNode.prev + " #$#@ "+currentNode.next);
				if(null!=currentNode.prev){
					currentNode.prev.next=currentNode.next; 
				} else {
					head.next=currentNode.next;
				}
				if(null!=currentNode.next){
					currentNode.next.prev=currentNode.prev; 
				} else {
					tail.prev=currentNode.prev;
				}
				System.out.println("currentNode to be returned= " + currentNode.data + " Prev to currentNode = "
						+ currentNode.prev + " next to currentNode =" + currentNode.next);
			}
			size--; 
		}		
		return currentNode.data;		
	}
public E remove ( int index ) { /*
		 * Algorithm:
		 * Check if the index is not out of bound: (for an empty list) : throw IndexOutOfBoundException
		 * index<0 || index>=size throw IndexOutOfBoundException
		 * initialize currentNode:head
		 * Initialize counter i to iterate the list from the start to index : i=0
		 * for each iteration check:
		 * currentNode=currentNode.next;
		 * 
		 */ LLNode < E > currentNode = null ; if ( index < 0 || ( index >= 0 && index >= size ) ) { throw new IndexOutOfBoundsException ( ) ; } else { currentNode = head ; for ( int i = 0 ; i <= index ; i ++ ) { currentNode = currentNode . next ; } if ( size ( ) == 1 ) { head . next = currentNode . next ; tail . prev = currentNode . prev ; } else { System . out . println ( " #$%$ size=" + size ( ) ) ; System . out . println ( " currentNode =" + currentNode + " @$#@#$@ " + currentNode . prev + " #$#@ " + currentNode . next ) ; if ( null != currentNode . prev ) { currentNode . prev . next = currentNode . next ; } else { head . next = currentNode . next ; } if ( null != currentNode . next ) { currentNode . next . prev = currentNode . prev ; } else { tail . prev = currentNode . prev ; } System . out . println ( "currentNode to be returned= " + currentNode . data + " Prev to currentNode = " + currentNode . prev + " next to currentNode =" + currentNode . next ) ; } size -- ; } return currentNode . data ; }
Remove a node at the specified index and return its data element.
Remove a node at the specified index and return its data element .
//System.out.println(" negative index ="+index); // list has only 1 element // list has greater than 1 element // check if the element being removed is the first element in the list then prev is null // setting the currentNode's prev node point to the next node // and you can't access the prev through currentNode but head // check if the element being removed is the last element in the list then next is null //setting the next node to point to currentNode's prev // and you can't access the next through currentNode but tail // decreasing the size by 1