int maxargs(A_stm stm){ Stack * S; Node * t; int max = 0; S = creat_stack(); maxargsStm(stm,S); t = pop(S); while(t){ if(max < t->s) max = t->s; t = pop(S); } return max; }
int main() { int i; stack *s; s=creat_stack(5); push(1,s); push(2,s); push(3,s); push(4,s); //pop(s); push(5,s); Display(s); push(6,s); return 0; }
int main(int argc, const char *argv[]) { mstack_t *sp; int i; data_t buf; sp = creat_stack(6); for(i = 0 ; i < 10;i ++){ push_stack(sp,&i); } print_stack(sp); pop_stack(sp,&buf); printf("pop : %d\n",buf); pop_stack(sp,&buf); printf("pop : %d\n",buf); pop_stack(sp,&buf); printf("pop : %d\n",buf); print_stack(sp); return 0; }
int main(int argc, char *argv[]){ FILE *handle; char cn; STACK S1, S2, S3, S4; int err_s1 = 0, err_s2 = 0, err_s3 = 0, err_s4 = 0; if(argc != 2){ printf("usage: ./name filename\n"); exit(1); } S1 = creat_stack(); /* for ()*/ S2 = creat_stack(); /* for {}*/ S3 = creat_stack(); /* for []*/ S4 = creat_stack(); /* for itself */ /* open source file*/ handle = fopen(argv[1], "r"); if(!handle){ perror("canot open source file\n"); exit(1); } else printf("open source file successful\n"); while(!feof(handle)){ cn = fgetc(handle); switch(cn){ case '(': push(S1, '('); break; case ')': err_s1 = pop(S1); break; case '{': push(S2, '{'); break; case '}': err_s2 = pop(S2); break; case '[': push(S3, '['); break; case ']': err_s3 = pop(S3); break; case '/': cn = fgetc(handle); if(cn == '*') push(S4, '*'); break; case '*': cn = fgetc(handle); if(cn == '/') err_s4 = pop(S4); break; } if(err_s1){ printf("miss '(' error\n"); exit(1); } if(err_s2){ printf("miss '{' error\n"); exit(1); } if(err_s3){ printf("miss '[' error\n"); exit(1); } if(err_s4){ printf("miss '/*'error\n "); exit(1); } } if(!(is_empty(S1))){ printf("miss ')'\n"); } if(!(is_empty(S2))){ printf("miss '}'\n"); } if(!(is_empty(S3))){ printf("miss ']'\n"); } if(!(is_empty(S4))){ printf("miss '*/'\n"); } if(is_empty(S1)&&is_empty(S2)&&is_empty(S3)&&is_empty(S4)) printf("check okay\n"); return 0; }