codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#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 a stack empty s bool emptystack(TStack s); // returns T if s stack is empty or F, otherwise void push(TStackKey k, TStack *s); // stacking on the stack key k 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 void createstack(TStack *s){ s->depth = 0; } bool emptystack(TStack s){ return s.depth == 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){ return s.depth; } void printstack(TStack *s, char *t){ TStack tmp; TStackKey k; printf("%s ", t); if (emptystack(*s)) printf("Vazia!\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); } }
Private
[
?
]
Run code
Submit