[ create a new paste ] login | about

Link: http://codepad.org/NZQ0TMJU    [ raw code | output | fork ]

C++, pasted on Oct 28:
void sort(TStack pilha) {
    TStack pilhaAux; // auxiliary stack to stack elements "stack"
    TSatck pilhaOrd; // keep the numbers in order
    TStackKey maior; // keep the largest number
    TStackKey topo;  // keep the top of the stack

    createstack(&pilhaAux);
    createstack(&pilhaOrd);

    TStackKey tam = pilha.depth; // keep the size of the "stack" in "tam"

    while(pilhaOrd.depth != tam) {

        topo = top(pilha);

        // Here you will find the largest number
        while (!emptystack(pilha)) {
            if (top(pilha) > topo && top(pilha) != topo)
                maior = top(pilha);

            push(pop(&pilha), &pilhaAux);
        }

        printstack(&pilhaAux, (char*)"pilhaAuxFormada: ");
        printf ("\n");

        push(maior, &pilhaOrd);
        printstack(&pilhaOrd, (char*)"Pilha ordenada: ");

        // here again the numbers will stack in "stack"
        while (!emptystack(pilhaAux)) {
            if (maior == top(pilhaAux))
                pop(&pilhaAux);
            else
                push(pop(&pilhaAux), &pilha);

            printstack(&pilhaAux, (char*)"pilhaAux: ");
            printstack(&pilha, (char*)"pilha: ");
        }

        printstack(&pilha, (char*)"Pilha volta: ");
    }



    printstack(&pilhaOrd, (char*)"Pilha ordenada: ");
}


Output:
1
2
Line 1: error: variable or field 'sort' declared void
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: