int main() { int N = 50; srand(time(0)); stack *s = StackNew(); printf("Node size = %ld Stack size = %ld\n", sizeof(node), sizeof(stack)); for (int i = 0; i < N; i++) { printf("Push %d\n", i); StackPush(s, i); } StackPrint(s); for (int i = 0; i < N; i++) { int n = StackPop(s); printf("Pop %d\n", n); if (i % 2 == 0) printf("Peek = %d\n", StackPeek(s)); } printf("Size = %d\n", s->size); StackFree(s); long sum = sizeof(node) * 50 + sizeof(stack); printf("%ld total bytes\n", sum); }
void PrintTop(queue* q) { if(StackEmpty(q->a)) { while(!StackEmpty(q->b)) { StackPush(q->a, StackPop(q->b)); } } StackPrint(q->a); }
int main(){ int Option=1, Value, i; while(Option){ printf("1) PUSH Stack\n2) POP Stack\n3) Print Stack\n4) Peep\n5) Change Stack\n0) Exit program\n"); scanf("%d", &Option); switch(Option){ case 1: do{ printf("Enter a +ve value: "); scanf("%d", &Value); }while(Value<0); Push(Value); /* allow possitive values */ printf("Stack PUSHed\n\n"); break; case 2: Pop(); printf("Stack POPed\n\n"); break; case 3: StackPrint(); break; case 4: printf("Enter a valid index: "); scanf("%d", &Value); Value = Peep(Value); if(Value) printf("Value at asked index: %d\n\n", Value); else printf("wrong index\n\n"); break; case 5: printf("Enter a valid index & value: "); scanf("%d %d", &i, &Value); Change(i,Value); printf("Value changed\n\n"); break; case 0: DeleteStack(); break; default: printf("Enter a valid choice\n\n"); break; } } return 1; }