6- prove safety offer- face questions from start to finish printing list - the list

/ * 
Title: 
	an input node of a head of the list, in turn, the print head from the tail value for each node 
* / 
/ * 
idea: 
	characteristic LIFO stack using: a solution. 
	Solution 2: Using nature of the recursive function. 
* / 
	
Void PrintListReversingly_Iteratively (ListNode * PHEAD) { 
	STD :: Stack <ListNode> Nodes; 
	ListNode * • pNode = PHEAD; 
	
	the while (! • pNode = null) { 
		nodes.push (• pNode); 
		• pNode = pNode-> Next; 
	} 
	
	the while ( ! nodes.empty ()) { 
		• pNode nodes.top = (); 
		the printf ( "% D \ T", pNode-> value); 
		nodes.pop () 
	} 
} 

void PrintListReversingly_Recursively (ListNode * PHEAD) { 
	IF (PHEAD! null =) { 
		PrintListReversingly_Recursively (pHead-> Next);  
		the printf ( "% D \ T", pHead-> value);
	} 
}

   

Guess you like

Origin www.cnblogs.com/buaaZhhx/p/11808642.html