Skip to main content
Formatação de código 3
Fonte Link
    int main () {
        ELEMENT ELEMENT, ELEMENT2, ELEMENT3;

        STACK stack;

        ELEMENT.key = 5;
        ELEMENT2.key = 7;
        ELEMENT3.key = 2;

        startStack(&stack);
        push(&stack, &ELEMENT);
        push(&stack, &ELEMENT2);
        push(&stack, &ELEMENT3);
        //pop(&stack); - ERRO, COMPILADOR FICAR EM LOOPING OU RETORNA UM EXIT CODE != 0
        //restartStack(&stack); - ERRO, COMPILADOR FICAR EM LOOPING OU RETORNA UM EXIT CODE != 0

        printf("%d\n", stackLenght(&stack));

        showElements(&stack);
}
    int main () {
        ELEMENT ELEMENT, ELEMENT2, ELEMENT3;

        STACK stack;

        ELEMENT.key = 5;
        ELEMENT2.key = 7;
        ELEMENT3.key = 2;

        startStack(&stack);
        push(&stack, &ELEMENT);
        push(&stack, &ELEMENT2);
        push(&stack, &ELEMENT3);
        //pop(&stack); - ERRO, COMPILADOR FICAR EM LOOPING OU RETORNA UM EXIT CODE != 0
        //restartStack(&stack); - ERRO, COMPILADOR FICAR EM LOOPING OU RETORNA UM EXIT CODE != 0

        printf("%d\n", stackLenght(&stack));

        showElements(&stack);
}
int main () {
        ELEMENT ELEMENT, ELEMENT2, ELEMENT3;

        STACK stack;

        ELEMENT.key = 5;
        ELEMENT2.key = 7;
        ELEMENT3.key = 2;

        startStack(&stack);
        push(&stack, &ELEMENT);
        push(&stack, &ELEMENT2);
        push(&stack, &ELEMENT3);
        //pop(&stack); - ERRO, COMPILADOR FICAR EM LOOPING OU RETORNA UM EXIT CODE != 0
        //restartStack(&stack); - ERRO, COMPILADOR FICAR EM LOOPING OU RETORNA UM EXIT CODE != 0

        printf("%d\n", stackLenght(&stack));

        showElements(&stack);
}
Arrumando código 2
Fonte Link

main:

    int main () {
        ELEMENT ELEMENT, ELEMENT2, ELEMENT3;

        STACK stack;

        ELEMENT.key = 5;
        ELEMENT2.key = 7;
        ELEMENT3.key = 2;

        startStack(&stack);
        push(&stack, &ELEMENT);
        push(&stack, &ELEMENT2);
        push(&stack, &ELEMENT3);
        //pop(&stack); - ERRO, COMPILADOR FICAR EM LOOPING OU RETORNA UM EXIT CODE != 0
        //restartStack(&stack); - ERRO, COMPILADOR FICAR EM LOOPING OU RETORNA UM EXIT CODE != 0

        printf("%d\n", stackLenght(&stack));

        showElements(&stack);
}

main:

    int main () {
        ELEMENT ELEMENT, ELEMENT2, ELEMENT3;

        STACK stack;

        ELEMENT.key = 5;
        ELEMENT2.key = 7;
        ELEMENT3.key = 2;

        startStack(&stack);
        push(&stack, &ELEMENT);
        push(&stack, &ELEMENT2);
        push(&stack, &ELEMENT3);
        //pop(&stack); - ERRO, COMPILADOR FICAR EM LOOPING OU RETORNA UM EXIT CODE != 0
        //restartStack(&stack); - ERRO, COMPILADOR FICAR EM LOOPING OU RETORNA UM EXIT CODE != 0

        printf("%d\n", stackLenght(&stack));

        showElements(&stack);
}
Arrumando código
Fonte Link
#include <stdio.h>
#include <malloc.h>

#define TRUE 0
#define FALSE 1
#define DEBUG
#undef DEBUG
typedef int TYPEKEY;


typedef struct {
    TYPEKEY key;
    struct aux*ELEMENT* next;
} ELEMENT;

typedef struct {
    ELEMENT *top;
} STACK;

void startStack (STACK *stack) {
    stack->top = NULL;
}

int stackLenght (STACK *stack) {
    ELEMENT *element = stack->top;
    int lenght = 0;

    while (element != NULL) {
        element = element->next;
        lenght++;
    }

    return lenght;
}

int isEmpty (STACK *stack) {
    return stack->top == NULL ? TRUE : FALSE;
}

void showElements (STACK *stack) {
    ELEMENT *element = stack->top;

    while (element != NULL) {
        printf("%d ", element->key);
        element = element->next;
    }

    printf("\n");
}

void push (STACK *stack, ELEMENT *elementToInsert) {

    /* Aloca memória */
    ELEMENT *aux = (ELEMENT*) malloc(sizeof(ELEMENT));
    /* Guarda o antigo topo */
    aux = stack->top;

    /* O novo elemento é o topo*/
    stack->top = elementToInsert;

    /* O antigo topo é o next */
    elementToInsert->next = aux;

}

int pop (STACK *stack) {

    if (stack->top != NULL) {
        ELEMENT *aux = stack->top;
        stack->top = stack->top->next;
        free(aux);

        return TRUE;
    }

    return FALSE;
}

ELEMENT* topStack (STACK *stack) {
    return stack->top != NULL ? stack->top : NULL;
}

void restartStack (STACK *stack) {
    ELEMENT *position = stack->top;

    while (position != NULL) {
        ELEMENT *remove = position;
        position = position->next;
        free(remove);
    }

    stack->top = NULL;

}
#include <stdio.h>
#include <malloc.h>

#define TRUE 0
#define FALSE 1
#define DEBUG
#undef DEBUG
typedef int TYPEKEY;


typedef struct {
    TYPEKEY key;
    struct aux* next;
} ELEMENT;

typedef struct {
    ELEMENT *top;
} STACK;

void startStack (STACK *stack) {
    stack->top = NULL;
}

int stackLenght (STACK *stack) {
    ELEMENT *element = stack->top;
    int lenght = 0;

    while (element != NULL) {
        element = element->next;
        lenght++;
    }

    return lenght;
}

int isEmpty (STACK *stack) {
    return stack->top == NULL ? TRUE : FALSE;
}

void showElements (STACK *stack) {
    ELEMENT *element = stack->top;

    while (element != NULL) {
        printf("%d ", element->key);
        element = element->next;
    }

    printf("\n");
}

void push (STACK *stack, ELEMENT *elementToInsert) {

    /* Aloca memória */
    ELEMENT *aux = (ELEMENT*) malloc(sizeof(ELEMENT));
    /* Guarda o antigo topo */
    aux = stack->top;

    /* O novo elemento é o topo*/
    stack->top = elementToInsert;

    /* O antigo topo é o next */
    elementToInsert->next = aux;

}

int pop (STACK *stack) {

    if (stack->top != NULL) {
        ELEMENT *aux = stack->top;
        stack->top = stack->top->next;
        free(aux);

        return TRUE;
    }

    return FALSE;
}

ELEMENT* topStack (STACK *stack) {
    return stack->top != NULL ? stack->top : NULL;
}

void restartStack (STACK *stack) {
    ELEMENT *position = stack->top;

    while (position != NULL) {
        ELEMENT *remove = position;
        position = position->next;
        free(remove);
    }

    stack->top = NULL;

}
#include <stdio.h>
#include <malloc.h>

#define TRUE 0
#define FALSE 1
#define DEBUG
#undef DEBUG
typedef int TYPEKEY;


typedef struct {
    TYPEKEY key;
    struct ELEMENT* next;
} ELEMENT;

typedef struct {
    ELEMENT *top;
} STACK;

void startStack (STACK *stack) {
    stack->top = NULL;
}

int stackLenght (STACK *stack) {
    ELEMENT *element = stack->top;
    int lenght = 0;

    while (element != NULL) {
        element = element->next;
        lenght++;
    }

    return lenght;
}

int isEmpty (STACK *stack) {
    return stack->top == NULL ? TRUE : FALSE;
}

void showElements (STACK *stack) {
    ELEMENT *element = stack->top;

    while (element != NULL) {
        printf("%d ", element->key);
        element = element->next;
    }

    printf("\n");
}

void push (STACK *stack, ELEMENT *elementToInsert) {

    /* Aloca memória */
    ELEMENT *aux = (ELEMENT*) malloc(sizeof(ELEMENT));
    /* Guarda o antigo topo */
    aux = stack->top;

    /* O novo elemento é o topo*/
    stack->top = elementToInsert;

    /* O antigo topo é o next */
    elementToInsert->next = aux;

}

int pop (STACK *stack) {

    if (stack->top != NULL) {
        ELEMENT *aux = stack->top;
        stack->top = stack->top->next;
        free(aux);

        return TRUE;
    }

    return FALSE;
}

ELEMENT* topStack (STACK *stack) {
    return stack->top != NULL ? stack->top : NULL;
}

void restartStack (STACK *stack) {
    ELEMENT *position = stack->top;

    while (position != NULL) {
        ELEMENT *remove = position;
        position = position->next;
        free(remove);
    }

    stack->top = NULL;

}
Post restaurado por Staniack
Post removido por Staniack
Fonte Link
Carregando