Загрузка данных


#include <stdio.h>
#include "stack.h"

void test_push(void) {
    struct stack_node *root = init(1);
    struct stack_node *new_root = push(root, 2);
    int success = 0;

    if (new_root != NULL && new_root->value == 2 && new_root->next == root) {
        success = 1;
    }

    if (success) {
        printf("push: SUCCESS\n");
    } else {
        printf("push: FAIL\n");
    }

    destroy(new_root);
}

void test_pop(void) {
    struct stack_node *root = init(1);
    struct stack_node *new_root = push(root, 2);
    struct stack_node *after_pop = pop(new_root);
    int success = 0;

    if (after_pop == root && after_pop->value == 1 && after_pop->next == NULL) {
        success = 1;
    }

    if (success) {
        printf("pop: SUCCESS\n");
    } else {
        printf("pop: FAIL\n");
    }

    destroy(after_pop);
}

int main(void) {
    test_push();
    test_pop();
    return 0;
}