void conversion() {
pSqStack S;
SElemType e;
int n;
InitStack(&S);
printf("Input a number to convert to OCT:\n");
scanf("%d",&n);
if(n<0)
{ printf("\nThe number must be over 0.");
return;}
if(!n) Push(S,0);
while(n){
Push(S,n%8);
n=n/8; }
printf("the result is: ");
while(!StackEmpty(*S)){
Pop(S,&e); printf("%d",e);}
}
|
void LineEdit() {
pSqStack S,T; char str[1000];
int strlen=0; char e; char ch;
InitStack(&S);
InitStack(&T);
ch=getchar();
while(ch!=EOFILE) {
while(ch!=EOFILE&&ch!='\n') {
switch(ch){
case '#': Pop(S,&ch); break;
case '@': ClearStack(S); break;
default: Push(S,ch); break; }
ch=getchar();
}
if(ch=='\n') Push(S,ch);
while(!StackEmpty(*S)) { Pop(S,&e); Push(T,e); }
while(!StackEmpty(*T)) { Pop(T,&e); str[strlen++]=e; }
if(ch!=EOFILE) ch=getchar();
}
str[strlen]='\0';
printf("\n%s",str);
DestroyStack(S);
DestroyStack(T);
}
|
char EvaluateExpression() {
SqStack *OPND,*OPTR;
char c,x,theta; char a,b;
InitStack(&OPTR); Push(OPTR,'#');
InitStack(&OPND);
c=getchar();
while(c!='#'||GetTop(*OPTR)!='#') {
if(!In(c,OP)) {Push(OPND,c);c=getchar();}
else
switch(Precede(GetTop(*OPTR),c)) {
case '<': Push(OPTR,c); c=getchar(); break;
case '=': Pop(OPTR,&x); c=getchar(); break;
case '>': Pop(OPTR,&theta);
Pop(OPND,&b); Pop(OPND,&a);
Push(OPND,Operate(a,theta,b));
break;
}
}
c=GetTop(*OPND);
DestroyStack(OPTR);
DestroyStack(OPND);
return c;
}
|