| 	
	
	
		
		|||||||
  | 
		
| 
 | 
![]()  | 
	
	
| 
		 | 
	Strumenti | 
| 		
			
			 | 
		#1 | 
| 
			
			
			
			 Senior Member 
			
		
			
				
			
			
			Iscritto dal: Jun 2005 
				Città: Napoli 
				
				
					Messaggi: 1661
				 
				
				
				
				 | 
	
	
	
	
		
			
			 
				
				altezza albero binario di ricerca
			 
			
		ciao raga ! sapete come devo fare per calcolarmi con una funzione ricorsiva l'altezza di un albero ovvero il cammino massimo di quest'ultimo ? tnk's 
		
	
		
		
		
		
			ps con pseudocodice 
				__________________ 
		
		
		
		
	
	 
			 | 
| 
		
 | 
	
	
	
		
		
		
		
		
		
			 
		
		
		
		
		
		
			
			
		
	 | 
| 		
			
			 | 
		#2 | 
| 
			
			
			
			 Bannato 
			
		
			
			
			Iscritto dal: Mar 2008 
				Città: Villabate(PA) 
				
				
					Messaggi: 2515
				 
				
				
				
				 | 
	
	
	
	
		
		
		
		 
		Versione ricorsiva: 
		
	
		
		
		
		
		
	
	Codice: 
	int TreeDepth(Tree* head)
{
	if ( head == NULL)
	{
		 return -1;
	}
	else
	{
		int lDepth = TreeDepth(head->left);
		int rDepth = TreeDepth(head->right);
		if (lDepth > rDepth)
			return (lDepth + 1);
		else
			return (rDepth + 1);
	}
}
Codice: 
	int TreeDepth(Tree *head)
{
	Tree *temp1, *temp2;
	int Conta;
	Tree *stack[MAX_STACK];
	int top;
	top = 0;
	Conta = 0;
 
	if ( head == NULL )
	{
		return -1;
	}
	temp1 = temp2 = head;
	while ( temp1 != NULL )
	{
		for(; temp1->left != NULL; temp1 = temp1->left)
		{
			stack[top++] = temp1;
			if ( Conta < top )
				Conta++;
		}
		while ( (temp1 != NULL) && (temp1->right == NULL || temp1->right == temp2) )
		{
			temp2 = temp1;
			if ( top == 0 )
				return Conta;
			temp1 = stack[--top];
		}
		stack[top++] = temp1;
		temp1 = temp1->right;
		if ( Conta < top )
			Conta = top;
	}
	return Conta + 1;
}
 | 
| 
		
 | 
	
	
	
		
		
		
		
		
		
			 
		
		
		
		
		
		
			
			
		
	 | 
| 		
			
			 | 
		#3 | 
| 
			
			
			
			 Senior Member 
			
		
			
				
			
			
			Iscritto dal: Jun 2005 
				Città: Napoli 
				
				
					Messaggi: 1661
				 
				
				
				
				 | 
	
	
	
	
		
		
		
		 
		tnk's  
		
	
		
		
		
		
			
				__________________ 
		
		
		
		
	
	 
			 | 
| 
		
 | 
	
	
	
		
		
		
		
		
		
			 
		
		
		
		
		
		
			
			
		
	 | 
		
		  
	   | 
| Strumenti | |
		
  | 
	
		
  | 
Tutti gli orari sono GMT +1. Ora sono le: 02:05.









		
		
		
			
 
 







