#include #include #include typedef struct _node { int element; struct _node *next; } node; typedef node *stack; stack init () { return NULL; } int isempty ( stack S ) { return (S == NULL); } int top ( stack S ) { if (isempty(S)) { printf("Error: top in an empty stack\n"); return -1; } return S -> element; } stack push ( stack S, int a ) { node *p; p = (node *)malloc(sizeof(node)); p -> element = a; p -> next = S; return p; } stack pop ( stack S ) { node *p; if (isempty(S)) { printf("Error: pop in an empty stack\n"); return S; } p = S; S = S -> next; free(p); return S; } int main ( ) { int A[100], n, NLV[100], t, i; stack S; srand((unsigned int)time(NULL)); printf("n = "); scanf("%d", &n); for (i=0; i A[t]) { NLV[t] = i; S = pop(S); } else { break; } } S = push(S,i); } for (i=0; i