using namespace std; #include #include "struct_stack.h" static boolean emptyp (stack s) { return (boolean) (s == NULL); } void init(stack & s) { s = NULL; } retval top (int &n,stack s) { if (emptyp(s)) return FAIL; n=s -> val; return OK; } retval push (int n,stack & s) { nodo * np = new nodo; if (np==NULL) return FAIL; np -> val = n; np -> next = s; s = np; return OK; } retval pop (stack & s) { if (emptyp(s)) return FAIL; nodo *first = s; s = s -> next; delete first; /* liberare la memoria: cancella l'oggetto puntato da first*/ return OK; } void print (stack s) { nodo *first = s; while (first!=NULL) { cout << first->val << " "; first = first -> next; } cout << endl; } void print_reverse (stack s) { nodo *first = s; if (first == NULL) return; else { print_reverse (first -> next); cout << first->val << " "; } }