c语言实现静态循环队列
2018-03-06 22:27
399 查看
#include<stdio.h>
#include<malloc.h>
typedef struct queue
{
int * Base;
int front;
int rear;
} QUEUE,*pQUEUE;
bool init(pQUEUE);
bool enter_queue(pQUEUE,int val);
bool full_queue(pQUEUE);
bool empty_queue(pQUEUE);
bool out_queue(pQUEUE);
bool traverse(pQUEUE);
int main()
{
QUEUE my;
init(&my);
enter_queue(&my,1);
enter_queue(&my,2);
enter_queue(&my,3);
enter_queue(&my,4);
enter_queue(&my,5);
traverse(&my);
out_queue(&my);
out_queue(&my);
traverse(&my);
return 0;
}
bool init(pQUEUE T)
{
T->Base=(int*)malloc(sizeof(int)*6);
if(T->Base==NULL)
return false;
T->front=0;
T->rear=0;
return true;
}
bool enter_queue(pQUEUE T,int val)
{
if(full_queue(T))
return false;
T->Base[T->rear%6]=val;
T->rear++;
return true;
}
bool full_queue(pQUEUE T)
{
if((T->rear+1)%6==T->front)
return true;
return false;
}
bool empty_queue(pQUEUE T)
{
if(T->front==T->rear)
return true;
return false;
}
bool traverse(pQUEUE T)
{
if(empty_queue(T))
return false;
for(int i=T->front;i!=T->rear;i=(i+1)%6)
printf("%d\n",T->Base[i]);
return true;
}
bool out_queue(pQUEUE T)
{
if(empty_queue(T))
return false;
T->front=(T->front+1)%6;
return true;
}
#include<malloc.h>
typedef struct queue
{
int * Base;
int front;
int rear;
} QUEUE,*pQUEUE;
bool init(pQUEUE);
bool enter_queue(pQUEUE,int val);
bool full_queue(pQUEUE);
bool empty_queue(pQUEUE);
bool out_queue(pQUEUE);
bool traverse(pQUEUE);
int main()
{
QUEUE my;
init(&my);
enter_queue(&my,1);
enter_queue(&my,2);
enter_queue(&my,3);
enter_queue(&my,4);
enter_queue(&my,5);
traverse(&my);
out_queue(&my);
out_queue(&my);
traverse(&my);
return 0;
}
bool init(pQUEUE T)
{
T->Base=(int*)malloc(sizeof(int)*6);
if(T->Base==NULL)
return false;
T->front=0;
T->rear=0;
return true;
}
bool enter_queue(pQUEUE T,int val)
{
if(full_queue(T))
return false;
T->Base[T->rear%6]=val;
T->rear++;
return true;
}
bool full_queue(pQUEUE T)
{
if((T->rear+1)%6==T->front)
return true;
return false;
}
bool empty_queue(pQUEUE T)
{
if(T->front==T->rear)
return true;
return false;
}
bool traverse(pQUEUE T)
{
if(empty_queue(T))
return false;
for(int i=T->front;i!=T->rear;i=(i+1)%6)
printf("%d\n",T->Base[i]);
return true;
}
bool out_queue(pQUEUE T)
{
if(empty_queue(T))
return false;
T->front=(T->front+1)%6;
return true;
}
相关文章推荐
- 数据结构基础(5)--C语言实现循环队列--静态
- c语言数组方式实现静态循环队列
- 数据结构:循环队列(C语言实现)
- 数据结构之---C语言实现循环队列
- C语言实现队(循环队列)
- 数据结构.循环队列(C语言实现)
- 循环队列及C语言实现<三>
- c语言:循环队列的实现
- 循环队列操作之一:循环队列的表示和实现(C语言版本)
- 数据结构:循环队列(C语言实现)
- 静态循环队列C++实现
- C语言实现使用动态数组实现循环队列
- 数据结构:循环队列(C语言实现)
- C语言实现循环队列
- 数据结构与算法分析—循环队列的数组实现(C语言)
- 数据结构 --静态队列的一个简单的C语言代码实现
- C语言 循环队列的实现
- C语言循环队列的表示与实现实例详解
- CycleQueue--循环队列(c语言简单实现)
- 循环队列–C语言实现–数据结构