Sort double circular list in c language

0

I'm trying to make a function that orders me a list of this type, so far I made one that orders a double list but I do not know how to change it so that it does what I want

This is the code of my function:

void ordena_lista(Nodo *nodo){

    Nodo *actual, *siguiente;
    int n;

    actual = nodo;
    while(actual->sig != NULL) {
      siguiente = actual->sig;
      while(siguiente != NULL) {
        if(actual->num < siguiente->num) {
          n = siguiente->num;
          siguiente->num = actual->num;
          actual->num = n;
        }
        siguiente = siguiente->sig;
      }
      actual = actual->sig;
      siguiente = actual->sig;
    }
  }
    
asked by Nutrii182 13.10.2018 в 20:06
source

1 answer

0

I'm going to assume that the node parameter that you pass to the function is the first one on the list.

Then the code I would solve it in the following way:

void ordena_lista(Nodo *nodo)
{
    int n;
    Nodo *actual, *siguiente;

    if(nodo != NULL)
    {
        actual = nodo;
        do
        {
            siguiente = actual->sig;
            while(siguiente != nodo)
            {
                if(actual->num > siguiente->num)
                {
                    n = siguiente->num;
                    siguiente->num = actual->num;
                    actual->num = n;
                }
                siguiente = siguiente->sig;
            }
            actual = actual->sig;
            siguiente = actual->sig;
        }
        while(siguiente != nodo);
    }
}
    
answered by 24.12.2018 в 16:31