Sequence_Cqueue(顺序循环队列)
来源:互联网 发布:千人基因组数据库 编辑:程序博客网 时间:2024/06/14 20:11
#include<stdio.h>
#define MAXSIZE 5
typedef int Datatype;
typedef struct {
Datatype a[MAXSIZE];
int front;
int rear;
}sequennce_cqueue;
void init(sequennce_cqueue *sq)
{
sq->front = 0;
sq->rear = 0;
}
int empty(sequennce_cqueue sq)
{
return (sq.front == sq.rear ? 1 : 0);
}
void display(sequennce_cqueue sq)
{
int i;
if (empty == 1)
printf("顺序表为空!\n");
else
{
if (sq.rear > sq.front)
{
for (i = sq.front; i < sq.rear; i++)
printf("%5d", sq.a[i]);
putchar('\n');
}
else
if(sq.rear < sq.front)
{
for (i = sq.front; i < MAXSIZE; i++)
printf("%5d", sq.a[i]);
for (i = 0; i < sq.rear; i++)
printf("%5d", sq.a[i]);
putchar('\n');
}
}
}
Datatype get(sequennce_cqueue sq)//取得队首的值
{
if (empty == 1)
{
printf("顺序表为空!,无法获取队首的值。\n");
return 0;
}
return sq.a[sq.front];
}
void insert(sequennce_cqueue *sq, Datatype x)
{
int i;
if ((sq->rear+1)%MAXSIZE==sq->front)
printf("队列已满,无法进行插入!\n");
else
{
sq->a[sq->rear] = x;
sq->rear = (sq->rear + 1) % MAXSIZE;
}
}
void dele(sequennce_cqueue *sq)
{
if (empty == 1)
{
printf("顺序表为空!,无法进行删除。\n");
}
else
sq->front=(sq->front+1)%MAXSIZE;
}
void main()
{
int i;
sequennce_cqueue SQ;
init(&SQ);
printf("队列空为1,非空为0:%d\n", empty(SQ));
for (i = 0; i < 5; i++)
insert(&SQ, i * 2);
display(SQ);
printf("队列空为1,非空为0:%d\n", empty(SQ));
printf("首部的元素为:%d\n", get(SQ));
dele(&SQ);
display(SQ);
printf("首部的元素为:%d\n", get(SQ));
insert(&SQ, 666);
display(SQ);
printf("首部的元素为:%d\n", get(SQ));
}
#define MAXSIZE 5
typedef int Datatype;
typedef struct {
Datatype a[MAXSIZE];
int front;
int rear;
}sequennce_cqueue;
void init(sequennce_cqueue *sq)
{
sq->front = 0;
sq->rear = 0;
}
int empty(sequennce_cqueue sq)
{
return (sq.front == sq.rear ? 1 : 0);
}
void display(sequennce_cqueue sq)
{
int i;
if (empty == 1)
printf("顺序表为空!\n");
else
{
if (sq.rear > sq.front)
{
for (i = sq.front; i < sq.rear; i++)
printf("%5d", sq.a[i]);
putchar('\n');
}
else
if(sq.rear < sq.front)
{
for (i = sq.front; i < MAXSIZE; i++)
printf("%5d", sq.a[i]);
for (i = 0; i < sq.rear; i++)
printf("%5d", sq.a[i]);
putchar('\n');
}
}
}
Datatype get(sequennce_cqueue sq)//取得队首的值
{
if (empty == 1)
{
printf("顺序表为空!,无法获取队首的值。\n");
return 0;
}
return sq.a[sq.front];
}
void insert(sequennce_cqueue *sq, Datatype x)
{
int i;
if ((sq->rear+1)%MAXSIZE==sq->front)
printf("队列已满,无法进行插入!\n");
else
{
sq->a[sq->rear] = x;
sq->rear = (sq->rear + 1) % MAXSIZE;
}
}
void dele(sequennce_cqueue *sq)
{
if (empty == 1)
{
printf("顺序表为空!,无法进行删除。\n");
}
else
sq->front=(sq->front+1)%MAXSIZE;
}
void main()
{
int i;
sequennce_cqueue SQ;
init(&SQ);
printf("队列空为1,非空为0:%d\n", empty(SQ));
for (i = 0; i < 5; i++)
insert(&SQ, i * 2);
display(SQ);
printf("队列空为1,非空为0:%d\n", empty(SQ));
printf("首部的元素为:%d\n", get(SQ));
dele(&SQ);
display(SQ);
printf("首部的元素为:%d\n", get(SQ));
insert(&SQ, 666);
display(SQ);
printf("首部的元素为:%d\n", get(SQ));
}
阅读全文
0 0
- Sequence_Cqueue(顺序循环队列)
- 循环队列(顺序队列)
- 循环队列(顺序队列)
- 顺序队列(循环队列)
- 循环队列(顺序表示)
- 顺序队列(非循环)
- 循环队列(顺序)二
- 循环队列(顺序)一
- C#实现循环顺序队列(队列)
- 线性表-顺序队列(循环队列)
- 数据结构之顺序队列(循环队列)
- java队列实现(顺序队列、链式队列、循环队列)
- java队列实现(顺序队列、链式队列、循环队列)
- 实验四:顺序队列(循环队列)和链队列
- java 顺序结构循环队列(源代码)
- 循环(顺序)队列存储实现
- SeqQueue--顺序循环队列
- 顺序循环队列
- 树莓派3-OpenCV+Picom摄像头
- IDEA不选择任何maven模板创建web项目
- 使用pyspark进行机器学习(聚类问题)
- UVa 1450 Airport (二分+思路)
- js中实现页面跳转(返回前一页、后一页)
- Sequence_Cqueue(顺序循环队列)
- 补录第一次写博客
- 数据结构与算法·实验一
- J
- 【温故知新-Java虚拟机篇】3.类文件结构
- LeetCode:Palindrome Number
- 二叉排序树 c
- 剑指Offer------链表中倒数第k个结点
- struts2中redirect和redirectAction的区别