I have 2 lists (one simple and one double), in the double implement the method of insertsort
without any problem and I would like to implement the same sorting method but in the simple list, the code is as follows.
Insert at start:
void Listaven::insertaInicio(Vendedor dato) {
Nodo * tmp = new Nodo;
tmp->guardaObjeto(dato);
tmp->guardaNodoSig(NULL);
bool nada = vacia();
if (nada) {
inicio = final = tmp;
}
else {
tmp->sig = inicio;
inicio->ant = tmp;
tmp->ant = NULL;
inicio = tmp;
}
ordenar();
int codigoVendedor = dato.damecodigoVendedor();
cout << "Has agregado un vendedor con el codigo: '" << codigoVendedor << "'" << endl;
}
Sorting method:
void Listaven::ordenar() {
Nodo *tmp = inicio;
Nodo *aux;
Vendedor recuperar;
while (tmp)
{
recuperar = tmp->dato;
aux = tmp;
while (aux->ant != NULL && recuperar.damecodigoVendedor()<aux->ant->dato.damecodigoVendedor())
{
aux->dato = aux->ant->dato;
aux = aux->ant;
}
aux->dato = recuperar;
tmp = tmp->sig;
}
}
This is how I have it to be able to sort it in the double linked list. What would be the way to implement it in the list simply linked, since therefore in the simple list there is no part ANT
only part SIG
.