
Untitled
By: a guest on
May 6th, 2012 | syntax:
None | size: 1.14 KB | hits: 22 | expires: Never
#include <stdlib.h>
#include <stdio.h>
#include "./inc/stack.h"
void push(struct node** first, struct node** addAfter, const char val){
struct node* top;
top = malloc(sizeof(struct node*));
top->val = val;
if(*first == NULL){
*first = top;
*addAfter = *first;
}
else{
(*addAfter)->next = top;
*addAfter = top;
}
}
char pop(struct node** first, struct node** last){
struct node* t;
if(*first == *last){
*first = *last = NULL;
return '\0';
}
for(t = *first; t != *last; t = t->next){
if(t->next == *last){
t->next = NULL;
*last = t;
break;
}
}
return t->val;
}
int isEmpty(struct node** first){
return *first == NULL;
}
void showStack(struct node* first){
struct node* t = NULL;
for(t = first; t != NULL; t = t->next){
printf("%c", t->val);
}
printf("\n");
}
int match(const char current, const char last){
int current_ascii, last_ascii;
current_ascii = current;
last_ascii = last;
if(current_ascii == (last_ascii + 1)){
return 1;
}
return 0;
}