56 lines
1005 B
C
56 lines
1005 B
C
//
|
|
// Created by nano on 4/30/25.
|
|
//
|
|
#include <stdio.h>
|
|
#include "stack.h"
|
|
|
|
|
|
/**
|
|
* Quick file to test all functions of the implemented stack.
|
|
*/
|
|
int main(void){
|
|
int ret =1;
|
|
stack stk;
|
|
stack_init(&stk);
|
|
|
|
BEGIN:
|
|
for (int i=0;i<=100;i++) {
|
|
cell c;
|
|
c.x = i;
|
|
c.y = 100-i;
|
|
stack_push(&stk, c);
|
|
printf("pushed: %d,%d\n",c.x,c.y);
|
|
}
|
|
stack_invert(&stk);
|
|
|
|
if (ret) {
|
|
printf("2nd run \n");
|
|
ret=0;
|
|
stack_reinit(&stk);
|
|
goto BEGIN;
|
|
}
|
|
stack_free(&stk);
|
|
|
|
printf("Append Test \n");
|
|
stack s1,s2;
|
|
stack_init(&s1);
|
|
stack_init(&s2);
|
|
for (int i=0;i<100;i++) {
|
|
stack_push(&s1,(cell){i,i});
|
|
stack_push(&s2,(cell){i,i});
|
|
}
|
|
for (int i=0;i<80;i++) {
|
|
stack_pop(&s1);
|
|
}
|
|
printf("s1 size: %d, s1 len: %d \ns2 size: %d, s2 len: %d \n",s1.size,s1.length,s2.size,s2.length);
|
|
stack_append(&s1,&s2);
|
|
printf("s2 size: %d, s2 len: %d \n",s2.size,s2.length);
|
|
while (s2.length) {
|
|
cell c = stack_pop(&s2);
|
|
printf("popped: %d,%d\n", c.x,c.y);
|
|
}
|
|
stack_free(&s1);
|
|
stack_free(&s2);
|
|
|
|
return 0;
|
|
} |