标签:
#define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 #include<stdio.h> #include<stdlib.h> typedef char SElemType; typedef struct{ SElemType *base,*top; int stacksize; }SqStack; int InitStack(SqStack &S) { S.base = (SElemType*)malloc(sizeof(SElemType) * STACK_INIT_SIZE); if(!S.base) exit(-2); S.base = S.top; S.stacksize = STACK_INIT_SIZE; return 1; }// int GetTop(SqStack S,SElemType &e) { if(S.base == S.top) return -1; e = *(S.top-1); return 1; } int Push(SqStack &S,SElemType e) { if(S.top - S.base >= S.stacksize) { S.base = (SElemType*)realloc(S.base,sizeof(SElemType) * (STACKINCREMENT + S.stacksize)); if(!S.base) exit(-2); S.top = S.base + S.stacksize; S.stacksize += STACKINCREMENT; } *S.top++ = e; return 1; } int Pop(SqStack &S,SElemType &e) { if(S.top <= S.base) return -1; e = *(--S.top); return 1; } int ClearStack(SqStack &S) { S.top = S.base ; return 1; } void ShowStack(SqStack S) { SElemType e; while(S.top > S.base) { Pop(S,e); printf("%c",e); } } int DestoryStack(SqStack &S) { free(S.base); S.base = NULL; S.top = NULL; S.stacksize = 0; } void LineEdit() { printf("欢迎进入文字输入练习系统:\n"); SqStack S; InitStack(S); char i = getchar(); Push(S,i); // char temp; // char ch = getchar(); // while(ch != EOF) // { // while(ch != EOF && ch != ‘\n‘) // { // switch(ch){ // case ‘#‘:Pop(S,temp);break; // case ‘@‘:ClearStack(S);break; // default : Push(S,ch);break; // } // ch = getchar(); // } // ClearStack(S); // if(ch != EOF) ch = getchar(); // } //DestoryStack(S); } int main() { LineEdit(); return 1; }
#define STACK_INIT_SIZE 100#define STACKINCREMENT 10#include<stdio.h>#include<stdlib.h>typedef char SElemType;typedef struct{SElemType *base,*top;int stacksize;}SqStack;int InitStack(SqStack &S){S.base = (SElemType*)malloc(sizeof(SElemType) * STACK_INIT_SIZE);if(!S.base) exit(-2);S.base = S.top;S.stacksize = STACK_INIT_SIZE;return 1;}//int GetTop(SqStack S,SElemType &e){if(S.base == S.top) return -1;e = *(S.top-1);return 1;}int Push(SqStack &S,SElemType e){if(S.top - S.base >= S.stacksize){S.base = (SElemType*)realloc(S.base,sizeof(SElemType) * (STACKINCREMENT + S.stacksize));if(!S.base) exit(-2);S.top = S.base + S.stacksize;S.stacksize += STACKINCREMENT;}*S.top++ = e;return 1;}int Pop(SqStack &S,SElemType &e){if(S.top <= S.base) return -1;e = *(--S.top);return 1;}int ClearStack(SqStack &S){S.top = S.base ; return 1;}void ShowStack(SqStack S){SElemType e;while(S.top > S.base){Pop(S,e);printf("%c",e);}}int DestoryStack(SqStack &S){free(S.base);S.base = NULL;S.top = NULL;S.stacksize = 0;}void LineEdit(){printf("欢迎进入文字输入练习系统:\n");SqStack S;InitStack(S);char i = getchar();Push(S,i); // char temp;// char ch = getchar();// while(ch != EOF)// {// while(ch != EOF && ch != ‘\n‘)// {// switch(ch){// case ‘#‘:Pop(S,temp);break;// case ‘@‘:ClearStack(S);break;// default : Push(S,ch);break;// }// ch = getchar();// }// ClearStack(S);// if(ch != EOF) ch = getchar();// } //DestoryStack(S);}
int main(){LineEdit();return 1;}
标签:
原文地址:http://www.cnblogs.com/minemine/p/5252123.html