Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/05/2010, 22:29
Avatar de extremoo
extremoo
 
Fecha de Ingreso: abril-2009
Mensajes: 54
Antigüedad: 15 años
Puntos: 0
Invertir Lista Recursivamente

Hola a todos espero puedan ayudarme con el siguiente ejercicio, trata de invertir una lista entregada, la idea es hacer el metodo y que reciba Nodolista x, mas abajo indicare el codigo pero mi idea es la siguiente.

x-> [1| ] -> [2| ] -> [3| ] -> [4| ] -> [5| ] -> NULL
___________________________________________
LO QUE ESTA CON COLOR NARANJO ES LA POSICION DONDE SE ENCUENTRA EL PUNTERO X
LO QUE ESTA CON COLOR VERDE EL LA POSICION DEL AUXILIAR2(AUX2)


x-> [1| ] -> [2| ] -> [3| ] -> [4| ] -> [5| ] -> NULL



aux1-> [1| ] -> [2| ] -> [3| ] -> [4| ] -> [5| ] -> NULL




aux1-> [1| ] -> NULL |||||||| x-> [2| ] -> [3| ] -> [4| ] -> [5| ] -> NULL


aux1-> [1| ] -> [2| ] -> [3| ] -> [4| ] -> [5| ] -> NULL

aplicar recursion

aux2->[2| ]-> aux1-> [1| ] ->NULL |||||| x -> [3| ] -> [4| ] -> [5| ] -> NULL

SI SE FIJAN LO QUE LE VA SOBRANDO A X ES LO QUE PASO EN EL ARGUMENTO PARA EJECUTAR LA RECURSION, soy bastante malo usando punteros lo que se me a ocurrido hasta el momento es lo siguiente. Si alguien se le ocurre como ayudar esta idea en java tambien es bienvenida, ojala puedan ayudarme saludos.


Código C:
Ver original
  1. void inverlista(Nodolista *x)
  2. {
  3. if ( x->sig==NULL )
  4. {
  5. return x;
  6. }
  7. if( x->sig!=NULL)
  8. {
  9. Nodolista aux1;
  10. x=x->sig;
  11. aux1=aux1->NULL;
  12. }
  13. while(x!=NULL)
  14. {
  15. Nodolista *aux2;
  16. x=x->sig;
  17. *aux2=aux2->aux1;
  18. }
  19. return inverlista(Nodolista x);
  20. }

Última edición por extremoo; 13/05/2010 a las 22:37