#include #include #include typedef struct { int T; int *element; int allocsize; } stack; stack init () { stack S; S.T = -1; S.element = (int *)malloc(sizeof(int)); S.allocsize = 1; return S; } int isempty ( stack S ) { return (S.T == -1); } int top ( stack S ) { if (isempty(S)) { printf("Error: top in an empty stack\n"); return -1; } return S.element[S.T]; } stack push ( stack S, int a ) { ++S.T; if (S.T >= S.allocsize) { S.allocsize *= 2; S.element = (int *)realloc(S.element, S.allocsize * sizeof(int)); } S.element[S.T] = a; return S; } stack pop ( stack S ) { if (isempty(S)) { printf("Error: pop in an empty stack\n"); return S; } --S.T; 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