All pastes #460623 Raw Edit

Something

public text v1 · immutable
#460623 ·published 2007-04-27 04:53 UTC
rendered paste body
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>


#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;
        sprintf(aux->nombre, nombre);
        sprintf(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;
        }
}

using namespace std;

int main() {
        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;
                                if (foo->ant != NULL) {
                                        foo->ant->sig = foo;
                                ]
                                if (aux->sig != NULL) {
                                        aux->sig->ant = aux;
                                }
                        }
                        foo = foo->sig;
                }
                aux = aux->sig;
        }


        aux = start;

        while (aux != NULL) {
                cout << "Producto: '" << aux->nombre << "' (genero: '" << aux->genero << "')\n";
                aux = aux->sig;
        }

        aux = end;
        while (aux != NULL) {
                cout << "Producto: '" << aux->nombre << "' (genero: '" << aux->genero << "')\n";
                aux = aux->ant;
        }

        aux = start;
        while (aux != NULL) {
                producto *tmp = aux->sig;
                delete aux;
                aux = tmp;
        }
}