dequeue_1.cpp
来自「《数据结构》所有相关程序的算法。有图、数组以及二叉数的问题。附有程序及结果。」· C++ 代码 · 共 59 行
CPP
59 行
//DeQueue.cpp
//This program is to delete the first element of the SqQueue
# include <malloc.h>
# include <iostream.h>
# include <conio.h>
# define MAXQSIZE 100
# define OK 1
# define ERROR 0
typedef int QElemType;
typedef struct SqQueue //define structure SqQueue
{ QElemType *base;
int front;
int rear;
}SqQueue;
int EnQueue(SqQueue &Q,QElemType e) //EnQueue() sub-function
{ if((Q.rear+1)%MAXQSIZE==Q.front)
{ cout<<"Errer ! The SqQeueu is full ! ";
return (ERROR);
}
Q.base[Q.rear]=e;
Q.rear=(Q.rear+1)%MAXQSIZE;
return (OK);
} //EnQueue() end
int DeQueue(SqQueue &Q,QElemType &e) //DeQueue() sub-function
{ if(Q.front==Q.rear)
{ cout<<endl<<"Errer ! It's empty!";
return (ERROR);
}
e=Q.base[Q.front];
Q.front=(Q.front+1)%MAXQSIZE;
return (e);
} //DeQueue() end
void main() //main() function
{ int i,e=1;
SqQueue Q;
Q.base=(QElemType *)malloc(MAXQSIZE*sizeof(QElemType));
Q.front=Q.rear=0;
cout<<endl<<endl<<"DeQueue.cpp";
cout<<endl<<"============="<<endl<<endl;
while(e)
{ cout<<"Please input the integer to insert (eg,58; 0 for exit) : ";
cin>>e;
if (e)
EnQueue(Q,e);
}
i=DeQueue(Q,e);
if(i)
cout<<endl<<"The first element is "<<i;
cout<<endl<<"The new SqQueue is : "; //output
for(e=Q.front;e<Q.rear;e++)
cout<<Q.base[e]<<" ";
cout <<endl<<endl<<"...OK!...";
getch();
} //main() end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?