public class LinkedListOps {

	/**
	 * Remove the specified node from the list.
	 * 
	 * @param head
	 *          head of the list (head != null)
	 * @param todel
	 *          node to remove (todel must be a node in the list)
	 * @return the head of the list after the removal
	 */
	public static ListNode remove ( ListNode head, ListNode todel ) {
		if ( head == null ) {
			throw new IllegalArgumentException("cannot remove from empty list");
		}
		
		// removing first node
		if ( head == todel ) {
			return todel.getNext();
		}
		
		ListNode before;  // node before todel
		for ( before = head ; before != null && before.getNext() != todel ; before = before.getNext()) {}
		if ( before == null ) {
			throw new IllegalArgumentException("cannot remove node not in the list");
		}
		
		ListNode after = todel.getNext();  // node after todel
		
		// relink
		before.setNext(after);
		
		return head;
	}

	/**
	 * Add the specified element at the head of the linked list, returning the new
	 * head of the list.
	 * 
	 * @param head
	 *          head of the list
	 * @param elt
	 *          element to insert
	 */
	public static ListNode insertAtHead ( ListNode head, int elt ) {
		return null;
	}

	/**
	 * Print the linked list.
	 * 
	 * @param head
	 *          head of the list
	 */
	public static void print ( ListNode head ) {}

	public static void main ( String[] args ) {
		ListNode head = null;

		int[] numbers = { 10, 40, 20, 30, 60, 70, 50 };
		for ( int i = 0 ; i < numbers.length ; i++ ) {
			head = insertAtHead(head,numbers[i]);
			print(head);
		}
		
	}

}