Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct stack stack;
- typedef struct node node;
- struct node {
- char sequence;
- node *next;
- };
- struct stack {
- node *top;
- };
- stack *create_stack() {
- stack *new_stack = (stack*) malloc(sizeof(stack));
- new_stack -> top = NULL;
- return new_stack;
- }
- void push(stack *stack, char sequence) {
- node *new_top = (node*) malloc(sizeof(node));
- new_top -> sequence = sequence;
- new_top -> next = stack -> top;
- stack -> top = new_top;
- return;
- }
- int pop(stack *stack) {
- if(stack -> top == NULL) {
- //printf("Stack is underflow.\n");
- return -1; // error code
- }
- else {
- //printf("%s\n", stack -> top -> sequence);
- stack -> top = stack -> top -> next;
- return 0; // success code
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement