/* Aca te mando el programa completo del que te habia hablado. */ // Recursion.cpp : Defines the entry point for the console application. // #include #include #include typedef struct L { int Dato; struct L* next; } *Lista, Nodo; void AltaNodo(Lista* MiLista, Nodo* NuevoNodo); Nodo* CrearNodo(); void ShowList(Lista MiLista); void DestroyList(Lista MiLista); int Maximo(Lista MiLista); int main(int argc, char* argv[]) { Lista MiLista = NULL; for( int i = 0; i<7 ; i++ ) { Nodo* NuevoNodo = CrearNodo(); AltaNodo(&MiLista, NuevoNodo ); } putchar('\n'); ShowList(MiLista); printf("\n\n^^^^^ Maximo: %d ^^^^^^\n", Maximo(MiLista) ); DestroyList(MiLista); MiLista = NULL; return 0; } void AltaNodo(Lista* MiLista, Nodo* NuevoNodo) { if( !*MiLista ) *MiLista = NuevoNodo; else AltaNodo( &((*MiLista)->next), NuevoNodo ); } Nodo* CrearNodo() { static first = 1; if( first ) { srand( (unsigned) time(NULL) ); first = 0; } Nodo* Nuevo = (Nodo*) malloc(sizeof(Nodo) ); Nuevo->next = NULL; Nuevo->Dato = rand() % 100; return Nuevo; } void ShowList(Lista MiLista) { if( MiLista ) { ShowList(MiLista->next); printf("%d\t", MiLista->Dato ); } else putchar('\n'); } void DestroyList(Lista MiLista) { if( MiLista ) { DestroyList( MiLista->next ); free(MiLista); } } int Maximo(Lista MiLista) { if( MiLista ) { int n = Maximo(MiLista->next); return ( MiLista->Dato > n ) ? MiLista->Dato : n; } return 0; }