lab4
来源:互联网 发布:storm1.0java源码 编辑:程序博客网 时间:2024/05/21 11:15
#include <malloc.h>
#include <iostream>
#define max 1000
using namespace std;
typedef struct celltype
{
int data;
celltype *next;
} cell;
struct QUEUE
{
celltype *f;
celltype *rear;
};
void MakeNull(QUEUE *Q)
{
cell *q = (cell*)malloc(sizeof(cell));
Q->f = q;
Q->f->next = NULL;
Q->rear = Q->f;
}
bool Empty(QUEUE *Q)
{
if (Q->f == Q->rear)
return true ;
else
return false;
}
void EnQueue(int x,QUEUE *Q)
{
cell *q = (cell*)malloc(sizeof(cell));
q->next=NULL;
q->data=x ;
q->next=Q->rear->next;
Q->rear->next=q;
Q->rear=q;
}
void DeQueue(QUEUE *Q)
{
celltype *p;
if (Q->rear==Q->f)
cout<<"队空";
else
{
cout<<Q->f->next->data<<endl;
p=Q->f->next;
Q->f->next=p->next;
}
if (p->next==NULL)
Q->rear=Q->f;
delete p;
}
int Front(QUEUE Q)
{
if(Q.f->next)
return Q.f->next->data;
}
int main()
{
struct QUEUE *Q = (QUEUE *)malloc(sizeof(QUEUE));
MakeNull(Q);
EnQueue(4,Q);
EnQueue(5,Q);
EnQueue(8,Q);
DeQueue(Q);
EnQueue(11,Q);
EnQueue(15,Q);
EnQueue(3,Q);
DeQueue(Q);
EnQueue(2,Q);
EnQueue(7,Q);
DeQueue(Q);
DeQueue(Q);
DeQueue(Q);
DeQueue(Q);
EnQueue(23,Q);
while(Empty(Q)!=true)
DeQueue(Q);
}
#include <iostream>
#define max 1000
using namespace std;
typedef struct celltype
{
int data;
celltype *next;
} cell;
struct QUEUE
{
celltype *f;
celltype *rear;
};
void MakeNull(QUEUE *Q)
{
cell *q = (cell*)malloc(sizeof(cell));
Q->f = q;
Q->f->next = NULL;
Q->rear = Q->f;
}
bool Empty(QUEUE *Q)
{
if (Q->f == Q->rear)
return true ;
else
return false;
}
void EnQueue(int x,QUEUE *Q)
{
cell *q = (cell*)malloc(sizeof(cell));
q->next=NULL;
q->data=x ;
q->next=Q->rear->next;
Q->rear->next=q;
Q->rear=q;
}
void DeQueue(QUEUE *Q)
{
celltype *p;
if (Q->rear==Q->f)
cout<<"队空";
else
{
cout<<Q->f->next->data<<endl;
p=Q->f->next;
Q->f->next=p->next;
}
if (p->next==NULL)
Q->rear=Q->f;
delete p;
}
int Front(QUEUE Q)
{
if(Q.f->next)
return Q.f->next->data;
}
int main()
{
struct QUEUE *Q = (QUEUE *)malloc(sizeof(QUEUE));
MakeNull(Q);
EnQueue(4,Q);
EnQueue(5,Q);
EnQueue(8,Q);
DeQueue(Q);
EnQueue(11,Q);
EnQueue(15,Q);
EnQueue(3,Q);
DeQueue(Q);
EnQueue(2,Q);
EnQueue(7,Q);
DeQueue(Q);
DeQueue(Q);
DeQueue(Q);
DeQueue(Q);
EnQueue(23,Q);
while(Empty(Q)!=true)
DeQueue(Q);
}
阅读全文
0 0
- lab4
- lab4
- Lab4 Authentication
- JOS-lab4
- ucore lab4
- Lab4: bootloader
- ucore lab4
- Lab3 and Lab4
- MIT6.828 Lab4 PartA
- MIT6.828 LAB4 PartB
- 操作系统 lab4 实验报告
- 操作系统实验报告 lab4
- OOAD Lab4实验文档
- 高软lab4
- 高软作业lab4
- csapp-lab4 cachelab
- [MIT6.828] LAB4 PART A
- MIT OS 8. MemLayout@ Lab4
- iOS SDK~ 打包framework、开发与调试
- Jstorm运维经验
- numpy中matrix和array的区别
- xutil 请求数据
- 广州企业网站建设中,千万不可忽视的重要事项!
- lab4
- SpringCloud微服务系列笔记(1)-SpringBoot简单入门
- 【机器学习系列之五】贝叶斯网络---图模型
- ** 多态与虚函数 编程题#3
- C++写窗口界面
- Android逆向之某拜蓝牙开锁原理探究
- mysql数据的安装以及数据库的操作
- 2017年ICPC亚洲区域赛青岛站
- Azkaban安装示例