#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
typedef struct Node {
int data;
Node *next;
}node;
typedef struct SeqQueue {
Node* front;
Node* rear;
}SQ;
void init(SQ* plist){
plist->front = (node*)malloc(sizeof(node));
plist->front->next = NULL;
plist->rear = plist->front;
}
void input(SQ* plist,int e){
node* newnode = (node*)malloc(sizeof(node));
newnode->data = e;
newnode->next = NULL;
plist->rear->next = newnode;
plist->rear = newnode;
}
void output(SQ* plist){
node* newnode = (node*)malloc(sizeof(node));
newnode = plist->front;
newnode = newnode->next;
plist->front = newnode;
}
void viewer(SQ* plist){
node* newnode = (node*)malloc(sizeof(node));
newnode = plist->front->next;
while(newnode != NULL){
printf("%d
",newnode->data);
newnode = newnode->next;
}
printf("
");
}
int main(int argc,char** argv) {
system("color 1e");
int select,data;
SQ* newplist = (SQ*)malloc(sizeof(SQ));
init(newplist);
while (1)
{
printf("1.入队
");
printf("2.出队
");
printf("3.遍历队列成员
");
printf("0.退出
");
printf("
请输入你要选择的功能
");
printf("您选择的功能为:");
scanf("%d", &select);
switch (select)
{
case 1:
printf("
请输入需要入队的数字:
");
scanf("%d", &data);
input(newplist,data);
break;
case 2: output(newplist);
break;
case 3: viewer(newplist);
break;
case 0:
printf("
程序已退出
");
exit(1);
break;
default:
printf("
输入错误!
请重新输入
");
break;
}
}
}