Example #1
0
	public static void reverseIterative(_<ListNode> list){
			
		if( list.value() == null)
			return ; 
				
		ListNode prev = null ; 	
		ListNode curr = list.value() ; 
		while( curr!=null){
			 ListNode next = curr.next ; 
			 curr.next = prev ; 
			 prev = curr ; 
			 curr = next ; 
		}
		list.set(prev); 
	}
Example #2
0
	public static void reverseRecursive(_<ListNode> list){
		
		if( list.value() == null )
			return ; 
		
		ListNode head = list.value(); 
		ListNode rest = head.next ; 
		if(rest==null)  // a singular list 
			return ; 
		
		_<ListNode> reversed = new _<ListNode>(rest); 
		reverseRecursive( reversed ); 
		head.next.next = head ; 
		head.next = null ; 
		list.set(reversed.value()); 
	} 
Example #3
0
	public static void createEvenLengthList(_<ListNode> head, _<ListNode> front, _<ListNode> tail){
		
		ListNode list   = new ListNode(6); 
		list.next       = new ListNode(5); 
		list.next.next  = new ListNode(4); 
		list.next.next.next  = new ListNode(3); 
		head.set(list);  
		
		ListNode frontList = new ListNode(6); 
		frontList.next = new ListNode(5);  
		front.set(frontList); 
		
		
		ListNode tailList = new ListNode(4); 
		tailList.next = new ListNode(3);  
		tail.set(tailList); 
	}