All pastes #918389 Raw Edit

Someone

public text v1 · immutable
#918389 ·published 2008-02-26 02:31 UTC
rendered paste body
template <typename Etype>
void List<Etype>::mixList(List<Etype> & secList) {
	ListNode* firstListTemp = NULL;
	ListNode* secListTemp = NULL;
	
	// corner cases
	if (secList.size == 0) return;
	if (size == 0) {
		head = secList.head;
		tail = secList.tail;
		size = secList.size;
	}
	else {
		current = head;
		
		while ((current != NULL) && (secList.current != NULL)) {
			
			// make first link between lists
			firstListTemp = current->next; // store next pointer in first list
			current->next = secList.current;
			secList.current->prev = current;
			current = firstListTemp; // move ahead in first list
			size++;
			
			if (current != NULL) { // note that current has been incremented
				
				// make second link between lists
				secListTemp = secList.current->next; // store next pointer in second list
				secList.current->next = current;
				current->prev = secList.current;
				secList.current = secListTemp; // move ahead in second list
			}
			else {
				tail = secList.tail;
				
				// for each remaining node in the second list, increment the first list's size
				while (secList.current != NULL) {
					size++;
					secList.current = secList.current->next;
				}
			}
		}
		
		// clean up second list
		secList.head = NULL;
		secList.tail = NULL;
		secList.size = 0;
	}
}