VC2010
电脑
头文件建立#include 'stdafx.h' #include
结构体的建立typedef struct QNode{ QElemType data; struct QNode * next;}QNode,*Queueptr;typedef struct{ Queueptr front; Queueptr rear;}LinkQueue;typedef char SElemType;typedef char QElemType;typedef struct{ SElemType *base; SElemType *top; int stacksize;}stack;
栈和对列的基本操作 char push(stack&s,SElemType e){ if (s.top -s.base >=s.stacksize ) { s.base =(SElemType*)realloc(s.base ,(s.stacksize +10)*sizeof(SElemType)); if(!s.base)exit(OVERFLOW); s.top =s.base +s.stacksize ; s.stacksize +=10; } *s.top ++=e; return 1;}char pop(stack&s,SElemType&e){if(s.top ==s.base )return 0; e=*--s.top ; cout<
结果 测试
栈和对列的建立char InitQueue(LinkQueue&q){ q.front =q.rear =(Queueptr)malloc(100*sizeof(QNode)); if(!q.front )exit(OVERFLOW); q.front ->next= NULL; return 1;}Queueptr p;char InitStack(stack&s){ s.base =(SElemType*)malloc(100*sizeof(SElemType)); if(!s.base )exit(OVERFLOW); s.top =s.base ; s.stacksize =100; return 1;}
主函数的调用int _tmain(int argc, _TCHAR* argv[]){ int x=0; QElemType f; LinkQueue q; SElemType a; stack s; InitStack(s); InitQueue(q); int b=0; char c[30]; cout<<'请?输º?入¨?串ä?'; cin>>c; while (c[b] != '@') { push(s,c[b]); EnQueue(q, c[b]); b++; } for (int i=0;i