voidDestoryStack(SqStack* sta){ if (sta) { free(sta); } }
voidPush(SqStack* sta) { int i; if (sta->top - sta->base == sta->stacksize) { printf("ERROR! Stack is full.\n"); } printf("Input the number you want to push in:\n"); scanf_s("%d", &i); setvbuf(stdin, NULL, _IOFBF, 512); *sta->top = i; /*printf("Position: %p\n", sta->top); printf("%d\n", *sta->top); Input: 2 Output: address, 2*/ sta->top++; // The auto increment operation on the pointer will change the address of the pointer accordingly (address + 4 bytes(one int) in length). /*printf("%d\n", *sta->top); printf("Position: %p\n", sta->top); Output: address+4, a rondom number*/ // The 50 line shows this is a linear stack. }
voidPop(SqStack* sta) { int e; if (sta->base == sta->top) { printf("ERROR!"); } --sta->top; e = *sta->top; printf("The number poped is %d\n", e); }