顺序表队列
以下为数据结构作业
如有错误,请指出,谢谢!1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using namespace std;
typedef int Status;
typedef int ElemType;
struct node
{
int num;
};
typedef struct
{
node *elem;
int length;
}SqList;
Status InitQueue(SqList &L)
{
L.elem=new node[MAXSIZE];
if(!L.elem)exit(OVERFLOW);
L.length=0;
return OK;
}
Status QueueShow(SqList &L)
{
for(int i=0;i<L.length;i++)
cout<<L.elem[i].num<<' ';
cout<<endl;
return OK;
}
Status EnQueue(SqList &L,node e)
{
if(L.length==MAXSIZE)return ERROR;
else
{
L.elem[L.length]=e;
++L.length;
return OK;
}
}
Status DeQueue(SqList &L)
{
for(int i=1;i<L.length;i++)
L.elem[i-1]=L.elem[i];
L.length--;
return 0;
}
void menu()
{
cout<<"1.EnQueue"<<endl;
cout<<"2.DeQueue"<<endl;
cout<<"0.Exit"<<endl;
}
int main()
{
SqList L;
node e;
int a,n;
InitQueue(L);
while(true)
{
system("CLS");
menu();
QueueShow(L);
cin>>a;
getchar();
if(a==1)
{
cout<<"Please Input Number To Be Insert:";
cin>>n;getchar();
e.num=n;
EnQueue(L,e);
}
else if(a==2)DeQueue(L);
else if(a==0)break;
}
return 0;
}