Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 1.14 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. #include "./inc/stack.h"
  5.  
  6. void push(struct node** first, struct node** addAfter, const char val){
  7.     struct node* top;
  8.  
  9.     top = malloc(sizeof(struct node*));
  10.     top->val = val;
  11.  
  12.     if(*first == NULL){
  13.         *first = top;
  14.         *addAfter = *first;
  15.     }
  16.     else{
  17.         (*addAfter)->next = top;
  18.         *addAfter = top;
  19.     }
  20.  
  21. }
  22.  
  23. char pop(struct node** first, struct node** last){
  24.     struct node* t;
  25.  
  26.     if(*first == *last){
  27.         *first = *last = NULL;
  28.         return '\0';
  29.     }
  30.  
  31.     for(t = *first; t != *last; t = t->next){
  32.         if(t->next == *last){
  33.             t->next = NULL;
  34.             *last = t;
  35.             break;
  36.         }
  37.     }
  38.  
  39.     return t->val;
  40. }
  41.  
  42. int isEmpty(struct node** first){
  43.     return *first == NULL;
  44. }
  45.  
  46. void showStack(struct node* first){
  47.     struct node* t = NULL;
  48.  
  49.     for(t = first; t != NULL; t = t->next){
  50.         printf("%c", t->val);
  51.     }
  52.  
  53.     printf("\n");
  54. }
  55.  
  56. int match(const char current, const char last){
  57.     int current_ascii, last_ascii;
  58.     current_ascii = current;
  59.     last_ascii = last;
  60.  
  61.     if(current_ascii == (last_ascii + 1)){
  62.         return 1;
  63.     }
  64.  
  65.     return 0;
  66. }