1、 e=*-s.top; return e;/*void conversion()/数制转换 int N; printf(请输入十进制数N:); scanf(%d,&N); Sqstack s; Initstack(s); while(N) Push(s,N%8); N=N/8; 转换的八进制为: while(s.top!=s.base) printf(,Pop(s);nvoid main() conversion();*/ int n; int temp;请输入初始化栈的元素个数:n); for(int i=1;inext=NULL;/创建栈void creat(LinkStack &top,
2、int n) int i; SNode *p;please input the data for LinkList Nodes: for(i=n;i0;i-) 输入%d个元素: p=(LinkStack)malloc(sizeof(SNode);p-data); p-next=top-next; top-next=p;/进栈操作void Push(LinkStack &top,char e) SNode *q; q=(LinkStack)malloc(sizeof(SNode); q-data=e;next=q;/出栈操作void Pop(LinkStack &top,char &e) e=t
3、op-next-data; q=top-next=q- free(q); void display(LinkStack & p=top; while(p-next!=NULL),p- p=p-/测试程序 char e,a; LinkStack stack1; Init(stack1);请输入括号以#号结束! while(1)%ca); if(a=#) break;(|a= Push(stack1,a); else if(a=) if(stack1-next=NULL) printf(括号不匹配! Push(stack1,a); break; Pop(stack1,e); if(e!= if(s
4、tack1- if(stack1-括号匹配!/链队列的基本操作typedef int QElemType;typedef struct QNode int data; struct QNode *next;QNode,*QueuePtr; QueuePtr front; QueuePtr rear;LinkQueue;/构造一个空队列 Qvoid InitQueue(LinkQueue &Q) Q.rear=Q.front=(QueuePtr)malloc(sizeof(QNode); Q.front-void EnQueue(LinkQueue &Q,int e) QNode *p; p=(
5、QueuePtr)malloc(sizeof(QNode); p- Q.rear- Q.rear=p;void DeQueue(LinkQueue &Q,int & p=Q.front- e=p-next=p- if(Q.rear=p) Q.rear=Q.front; free(p); LinkQueue Q; InitQueue(Q);你要入队的元素个数: int temp;输入第%d个元素: EnQueue(Q,temp);出队的元素为: while(!(Q.front=Q.rear) DeQueue(Q,e);,e);/应用栈和队列判断回文/栈void InitLinkStack(Lin
6、kStack &e1) e1=top-/队列Q,char e)Q,char &e2) e2=p-/回文判断函数int Huiwen(LinkStack &S,LinkQueue & char e1,e2; Pop(S,e1); DeQueue(Q,e2); if(S-next=NULL&Q.front=Q.rear) return 1; if(e1!=e2) return 0; char e,e1,e2; LinkStack S; InitLinkStack(S);请输入字符串:e); if(e=n Push(S,e); EnQueue(Q,e); /* printf(字符串是回文字符串!字符串不是回文字符串! */ int a; a=Huiwen(S,Q); if(a=1) else if(a=0)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1