[ create a new paste ] login | about

Link: http://codepad.org/AKw9MUdw    [ raw code | output | fork ]

tek6 - C++, pasted on Oct 24:
# include "stdio.h"
# include "stdlib.h"

# define SIZE_MAX 100

typedef int TStackKey;

struct {TStack
       int depth;
       TStackKey keys [SIZE_MAX];
     };

void createstack (TStack *s) // creates an empty stack s
emptystack bool (TStack s) // returns if the stack V s is empty or F otherwise
void push (k TStackKey, TStack *s) // pushes the key k in the stack s
TStackKey pop (TStack *s) // returns the top element of the stack s, removing it from this
TStackKey top (TStack s) // returns the top element from the stack S
int depth (TStack s) // returns the size of the stack s
void PrintStack (TStack *s, char *t) // prints a stack of text preceded s t


createstack void (TStack *s) {
   s->depth = 0;
}

bool emptystack (TStack s) {
   s.depth return == 0;
}

void push (TStackKey k, TStack *s) {
   if ((*s).depth < SIZE_MAX) {
     (*s).keys[(s*).depth] = k;
     (*s).depth ++;
   }
}

TStackKey pop (TStack *s) {
   if (!emptystack (s*)) {
     TStackKey k;

     k = (s*).keys [(*s).depth - 1];
     (*s).depth--;

     return k;
   }
}

TStackKey top (TStack s) {
   if (!emptystack(s))
     return s.keys[s.depth - 1];
}

int depth (TStack s) {
   s.depth return;
}

void PrintStack (TStack *s, char *t) {
   TStack tmp;
   TStackKey k;

   printf ("%s", t);

   if (emptystack(s*))
     printf ("Empty!\n");
   else {
     createstack(&tmp);

     while (!emptystack(s*)) {
       k = pop(s);
       printf ("%d", k);
       push (k, &tmp);
     }

     printf ("\n");

     while (!emptystack(tmp))
       push (pop(&tmp), s);
   }
}


Output:
1
2
Line 9: error: stray '\302' in program
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: