数据结构上机答案(4)

2019-02-15 19:37

if(S.base) return ERROR; S.top=S.base+S.stacksize; S.stacksize+=STACKINCREMENT; } *S.top++=e; return OK; }

Status Pop(SqStack &S,SElemType &e) { if(S.top==S.base) return ERROR; e=*--S.top; return OK; }

Status GetTop(SqStack S,SElemType &e) { if(S.top==S.base) return ERROR; e=*(S.top-1); return OK; }

int StackLength(SqStack S) { int i=0; while(S.top!=S.base) { i++; S.top--; } return i; }

Status StackTraverse(SqStack S) { SElemType *p=(SElemType*)malloc(sizeof(SElemType)); p=S.top; if(S.top==S.base) printf(\ else {

printf(\ p--; S.base--; while(p!=S.base) { printf(\ p--; } } printf(\ return OK; }

int main() { int a; SqStack S; SElemType x,e; if(InitStack(S)) printf(\ while(1) { printf(\the Top\\n4:Return the Length of the Stack\\n5:Load the Stack\\n0:Exit\\nPlease choose:\\n\ scanf(\ switch(a) { case 1:scanf(\ if(!Push(S,x)) printf(\ else printf(\ break; case 2:if(!Pop(S,e)) printf(\ else printf(\ break; case 3:if(!GetTop(S,e)) printf(\ else printf(\ break; case 4:printf(\

break; case 5:StackTraverse(S); break; case 0:return 1; } } }

2.2循环队列的基本操作 #include #include #define OK 1 #define ERROR 0 typedef int Status;

typedef int QElemType; #define MAXQSIZE 100

typedef struct { QElemType *base; int front; int rear; }SqQueue;

Status InitQueue(SqQueue &Q) { Q.base=(QElemType*)malloc(MAXQSIZE*sizeof(QElemType)); if(!Q.base) return ERROR; Q.front=Q.rear=0; return OK; }

Status EnQueue(SqQueue &Q,QElemType e) { if((Q.rear+1)%MAXQSIZE==Q.front) return ERROR; Q.base[Q.rear]=e; Q.rear=(Q.rear+1)%MAXQSIZE; return OK; }

Status DeQueue(SqQueue &Q,QElemType &e) { if(Q.front==Q.rear)

return ERROR; e=Q.base[Q.front]; Q.front=(Q.front+1)%MAXQSIZE; return OK; }

Status GetHead(SqQueue Q,QElemType &e) { if(Q.front==Q.rear) return ERROR; e=Q.base[Q.front]; return OK; }

int QueueLength(SqQueue Q) { return (Q.rear-Q.front+MAXQSIZE)%MAXQSIZE; }

Status QueueTraverse(SqQueue Q) { int i; i=Q.front; if(Q.front==Q.rear) printf(\ else { printf(\ while(i!=Q.rear) { printf(\ i=i+1; } } printf(\ return OK; }

int main() { int a; SqQueue S; QElemType x,e; if(InitQueue(S))

printf(\ while(1) { printf(\\\n2:Delete \\n3:Get the Front \\n4:Return the Length of the Queue\\n5:Load the Queue\\n0:Exit\\nPlease choose:\\n\ scanf(\ switch(a) { case 1: scanf(\ if(!EnQueue(S,x)) printf(\ else printf(\ break; case 2: if(!DeQueue(S,e)) printf(\ else printf(\ break; case 3: if(!GetHead(S,e)) printf(\ else printf(\ break; case 4: printf(\ break; case 5: QueueTraverse(S); break; case 0: return 1; } } }

2.3栈的应用——进制转换 #include #include #define ERROR 0 #define OK 1

#define STACK_INIT_SIZE 100 #define STACKINCREMENT 10

typedef int SElemType; typedef int Status;


数据结构上机答案(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:线塔3 混凝土电杆组立检查及评级记录表

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: