My bubble order does not work correctly, List doubly linked

1

As an activity I have to use a double linked list created by me, and likewise implement a bubble method to order the values.

My Node is this:

template<class T>
class NodoD{
    private:
        T dato;
        NodoD<T> *sig;
        NodoD<T> *ant;
    public:
        NodoD(const T &d){
            dato = d;
            sig = nullptr;
            ant = nullptr;
        }
        template <class> friend class ListaDoble;
    };

The bubble method of the list is:

template <class T>
void ListaDoble<T>::bubbleSort()
{
    NodoD<T> *current = primero;
    T dummy;

    if (current == NULL) return;
    if (current->sig == NULL) return;

    int swapped = 1;
    while (swapped){
        current = primero;
         //last pass unless there is a swap
        swapped = 0;
        while (current->sig != NULL){
            //swapped ++;
            if (current->dato > current->sig->dato){
                swapped = 1; //swap, will need to re-enter while loop
                //actual number swap
                dummy = current->dato;
                current->dato = current->sig->dato;
                current->sig->dato = dummy;
            }
            current = current->sig;
        }
        if (swapped)
            current = primero;
    }
}

What I want to order are some char *, the class is the following:

long int direccion;
char rfcProfe[13];
char estado[2];

Since they are char, overload the operators to be able to compare, converting all char to an integer:

bool Indice::operator ==(const Indice &i)
{
    int rfc = std::atoi(rfcProfe);
    int _rfc = std::atoi(i.rfcProfe);
    return rfc == _rfc;
}

bool Indice::operator !=(const Indice &i)
{
    int rfc = std::atoi(rfcProfe);
    int _rfc = std::atoi(i.rfcProfe);
    return rfc != _rfc;
}

bool Indice::operator <=(const Indice &i)
{
    int rfc = std::atoi(rfcProfe);
    int _rfc = std::atoi(i.rfcProfe);
    return rfc <= _rfc;
}

bool Indice::operator >=(const Indice &i)
{
    int rfc = std::atoi(rfcProfe);
    int _rfc = std::atoi(i.rfcProfe);
    return rfc >= _rfc;
}

bool Indice::operator <(const Indice &i)
{
    int rfc = std::atoi(rfcProfe);
    int _rfc = std::atoi(i.rfcProfe);
    return rfc < _rfc;
}

bool Indice::operator >(const Indice &i)
{
    int rfc = std::atoi(rfcProfe);
    int _rfc = std::atoi(i.rfcProfe);
    return rfc > _rfc;
}

The data entered are the following: link

And the data I obtain when doing the ordering, are the following: link

EDIT: Use quicksort in my list, and in the same way the bubble but there is an element that is not ordered. link

    
asked by Oscar D 14.09.2018 в 04:26
source

0 answers