suzy Posted May 14, 2008 at 11:24 AM Report Share #185002 Posted May 14, 2008 at 11:24 AM caros, tou com muita dificuldade nas funcoes recusrsivas,聽 estou a resolver problemas e pedia se pudessem 茅 claro ?, se estava correcto ou nao, vou ter exame e isto ta mto complicado聽 馃槥 1 - Desenvolva uma funcao recusriva em c, que determine quantos n贸s de uma arvore binaria e constituida por elementos do tipo no t锚m dois filhos. A fun莽茫o recebe como argumento um ponteiro para a razi da arvore binaria e devolve como resultado o valor calculdado fiz assim: int conta_nos(ptrre p) { 聽 聽 if(p==NULL) 聽 聽 聽 return 0; 聽 聽 else if(p->dir!=NULL && p->esq!=NULL) 聽 聽 聽 聽 聽 聽 聽 return 1+ conta_nos(p->dir)+conta_nos(p->esq); }; muito obrigada Link to comment Share on other sites More sharing options...
Warrior Posted May 14, 2008 at 01:18 PM Report Share #185031 Posted May 14, 2008 at 01:18 PM N茫o funciona para 谩rvores deste g茅nero: O primeiro n贸 tem um filho. Este filho, tem 2. Ou seja, o n煤mero de n贸s com 2 filhos 茅 1, e tu retornas 0. Link to comment Share on other sites More sharing options...
nata79 Posted May 15, 2008 at 05:48 PM Report Share #185327 Posted May 15, 2008 at 05:48 PM int conta_nos(ptrre p) { 聽 聽 if(p==NULL) 聽 聽 聽 return 0; 聽 聽 else if(p->dir!=NULL && p->esq!=NULL) 聽 聽 聽 聽 聽 聽 聽 return 1+ conta_nos(p->dir)+conta_nos(p->esq); 聽 聽 聽 聽 聽 else return conta_nos(p->dir)+conta_nos(p->esq); } s贸 acrescentar akele else ao segundo if e penso k fica a funcionar! arithmeticoverflow.wordpress.com Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now