<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
 * Node structure:
 *
 * Each node has a pointer to the min value at the time it was
 * added to the stack.
 */
typedef struct Node {
    int value;
    struct Node *prev;
    struct Node *min;
} Node;

/**
 * Stack structure:
 *
 * The stack keeps a pointer to the top.
 */
typedef struct Stack {
    Node *top;
} Stack;

void printStack(Node *curr);
void push(Stack *stack, Node *node);
void pop(Stack *stack);
int min(Stack *stack);
Node * createNode(int value);
Stack * createStack();

int main()
{
    Stack *stack = createStack();
    Node *a = createNode(15);
    Node *b = createNode(3);
    Node *c = createNode(2);
    Node *d = createNode(12);

    push(stack, a);
    push(stack, b);
    push(stack, c);
    push(stack, d);

    pop(stack);

    printStack(stack->top);
    printf("The minimum value in the stack is: %d\n", min(stack));

    return 0;
}

void printStack(Node *curr)
{
    if (curr == NULL) {
        return;
    }

    printf("%d, curr min: %d\n", curr->value, curr->min->value);
    printStack(curr->prev);
}

void push(Stack *stack, Node *node)
{
    node->prev = stack->top;
    stack->top = node;

    if (node->prev == NULL) {
        return;
    }

    // determine if the newest node is the new min node
    // in the future, consider doing this above for less de-referencing
    if (node->value < node->prev->min->value) {
        node->min = node;
    } else {
        node->min = node->prev->min;
    }
}

void pop(Stack *stack)
{
    stack->top = stack->top->prev;
}

int min(Stack *stack)
{
    return stack->top->min->value;
}

Node * createNode(int value)
{
   Node *newNode = (Node *)malloc(sizeof(Node));

   if (newNode == NULL) {
       printf("Error creating new node.\n");
       exit(0);
   }

   newNode->min = newNode;
   newNode->value = value;
   return newNode;
}

Stack * createStack()
{
    Stack *newStack = (Stack *)malloc(sizeof(Stack));

    if (newStack == NULL) {
        printf("Error creating new stack.\n");
        exit(0);
    }

    return newStack;
}
<commit_msg>casting malloc is not a thing i need to be doing<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
 * Node structure:
 *
 * Each node has a pointer to the min value at the time it was
 * added to the stack.
 */
typedef struct Node {
    int value;
    struct Node *prev;
    struct Node *min;
} Node;

/**
 * Stack structure:
 *
 * The stack keeps a pointer to the top.
 */
typedef struct Stack {
    Node *top;
} Stack;

void printStack(Node *curr);
void push(Stack *stack, Node *node);
void pop(Stack *stack);
int min(Stack *stack);
Node * createNode(int value);
Stack * createStack();

int main()
{
    Stack *stack = createStack();
    Node *a = createNode(15);
    Node *b = createNode(3);
    Node *c = createNode(2);
    Node *d = createNode(12);

    push(stack, a);
    push(stack, b);
    push(stack, c);
    push(stack, d);

    pop(stack);

    printStack(stack->top);
    printf("The minimum value in the stack is: %d\n", min(stack));

    return 0;
}

void printStack(Node *curr)
{
    if (curr == NULL) {
        return;
    }

    printf("%d, curr min: %d\n", curr->value, curr->min->value);
    printStack(curr->prev);
}

void push(Stack *stack, Node *node)
{
    node->prev = stack->top;
    stack->top = node;

    if (node->prev == NULL) {
        return;
    }

    // determine if the newest node is the new min node
    // in the future, consider doing this above for less de-referencing
    if (node->value < node->prev->min->value) {
        node->min = node;
    } else {
        node->min = node->prev->min;
    }
}

void pop(Stack *stack)
{
    stack->top = stack->top->prev;
}

int min(Stack *stack)
{
    return stack->top->min->value;
}

Node * createNode(int value)
{
   Node *newNode = malloc(sizeof(Node));

   if (newNode == NULL) {
       printf("Error creating new node.\n");
       exit(0);
   }

   newNode->min = newNode;
   newNode->value = value;
   return newNode;
}

Stack * createStack()
{
    Stack *newStack = malloc(sizeof(Stack));

    if (newStack == NULL) {
        printf("Error creating new stack.\n");
        exit(0);
    }

    return newStack;
}

{'fraction_non_alphanumeric': 0.15464403583215464, 'fraction_numerical': 0.004243281471004243, 'mean_word_length': 2.64206008583691, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1501505', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1428, 'n_words': 434}