#define LAXANTE 0 #define ANALGESICO 2 #define EYACULO_RETARDANTE 3 struct producto { char nombre[30]; char material[30]; int cantidad; int genero; producto *ant; producto *sig; }; producto *start=NULL; producto *end=NULL; void *push(char *nombre, char *material, int cantidad, int genero) { producto *aux = new producto; aux->ant = NULL; aux->sig = NULL; spintf(aux->nombre, nombre); spintf(aux->material, material); aux->cantidad = cantidad; aux->genero = genero; if (start == NULL) { start = aux; end = aux; } else { start->ant = aux; aux->sig = start; start = aux; } } push("Leche de Magnesia", "Plastico", 10, LAXANTE); push("Senokot", "Vidrio", 3, LAXANTE); push("Foto de sortadi", "Excrementos", 1, EYACULO_RETARDANTE); push("Acetaminofen", "Carton", 8, ANALGESICO); producto *aux = start; while (aux != NULL) { producto *foo = aux->sig; while (foo != NULL) { if (aux->genero > foo->genero) { aux->sig = foo->sig; foo->sig = aux; foo->ant = aux->ant; aux->ant = foo; } foo = foo->sig; } aux = aux->sig; } producto *aux = start; while (aux != NULL) { cout << "Producto: '" << aux->nombre << "' (genero: '" << aux->genero << "')"; aux = aux->sig; } producto *aux = end; while (aux != NULL) { cout << "Producto: '" << aux->nombre << "' (genero: '" << aux->genero << "')"; aux = aux->ant; }