Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
@大熊_
LearningDataStructure-Algorithm
提交
14253998
LearningDataStructure-Algorithm
项目概览
@大熊_
/
LearningDataStructure-Algorithm
通知
4
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
LearningDataStructure-Algorithm
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
14253998
编写于
11月 08, 2020
作者:
@大熊_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
顺序循环队列
上级
fbde5ebc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
176 addition
and
0 deletion
+176
-0
SeqQueue.c
SeqQueue.c
+150
-0
includes/SeqQueue.h
includes/SeqQueue.h
+26
-0
未找到文件。
SeqQueue.c
0 → 100644
浏览文件 @
14253998
/*
* @Description: 顺序循环队列
* @Author: 大熊人
* @LastEditTime: 2020-11-08 18:27:54
*/
#include <stdio.h>
#include <stdlib.h>
#include "includes/SeqQueue.h"
/**
* @description: 初始化顺序循环队列
* @param {struct *}Q
* @return {int}
*/
int
InitQueue
(
SeqQueue
*
Q
)
{
Q
->
base
=
(
QUEUE_DATA_TYPE
*
)
malloc
(
sizeof
(
QUEUE_DATA_TYPE
)
*
MAXSIZE
);
if
(
Q
->
base
==
NULL
)
{
return
FALSE
;
//申请内存空失败
}
Q
->
front
=
0
;
Q
->
rear
=
0
;
return
TRUE
;
}
/**
* @description: 判断队列是否为空
* @param {struct *}Q
* @return {int}
*/
int
IsEmpty
(
SeqQueue
*
Q
)
{
if
(
QueueLength
(
Q
)
==
0
)
{
return
TRUE
;
}
else
{
return
FALSE
;
}
}
/**
* @description: 判断队列是否满
* @param {struct *}Q
* @return {int}
*/
int
IsFull
(
SeqQueue
*
Q
)
{
if
(
QueueLength
(
Q
)
>
0
&&
Q
->
front
==
Q
->
rear
)
{
return
TRUE
;
}
else
{
return
FALSE
;
}
}
/**
* @description: 入列
* @param {struct *}Q
* @param {QUEUE_DATA_TYPE *}X
* @return {int}
*/
int
EnQueue
(
SeqQueue
*
Q
,
QUEUE_DATA_TYPE
X
)
{
if
(
IsFull
(
Q
)
==
TRUE
)
{
return
FALSE
;
//队列满
}
Q
->
base
[
Q
->
rear
]
=
X
;
Q
->
rear
=
(
Q
->
rear
+
1
)
%
MAXSIZE
;
//在MAXSIZE范围内指针后移
return
TRUE
;
}
/**
* @description: 出列
* @param {struct *}Q
* @param {QUEUE_DATA_TYPE *}X
* @return {int}
*/
int
DeQueue
(
SeqQueue
*
Q
,
QUEUE_DATA_TYPE
*
X
)
{
if
(
IsEmpty
(
Q
)
==
TRUE
)
{
return
FALSE
;
//队列空
}
*
X
=
Q
->
base
[
Q
->
front
];
Q
->
front
=
(
Q
->
front
+
1
)
%
MAXSIZE
;
//在MAXSIZE范围内指针后移
return
TRUE
;
}
/**
* @description: 获取队头元素
* @param {struct *}Q
* @return {int}
*/
int
GetFront
(
SeqQueue
*
Q
,
QUEUE_DATA_TYPE
*
X
)
{
if
(
IsEmpty
(
Q
)
==
TRUE
)
{
return
FALSE
;
}
*
X
=
Q
->
base
[
Q
->
front
];
return
TRUE
;
}
/**
* @description: 获取队列长度
* @param {struct}Q
* @return {int}
*/
int
QueueLength
(
SeqQueue
*
Q
)
{
return
(
Q
->
rear
-
Q
->
front
+
MAXSIZE
)
%
MAXSIZE
;
}
/**
* @description: 测试顺序循环队列
*/
void
TestSeqQueue
()
{
SeqQueue
Q
;
QUEUE_DATA_TYPE
value
;
if
(
InitQueue
(
&
Q
))
{
printf
(
"初始化成功!
\n
"
);
}
else
{
printf
(
"初始化失败!
\n
"
);
}
printf
(
"EnQueue:1 %s
\n
"
,
EnQueue
(
&
Q
,
1
)
?
"TURE"
:
"FALSE"
);
printf
(
"EnQueue:2 %s
\n
"
,
EnQueue
(
&
Q
,
2
)
?
"TURE"
:
"FALSE"
);
printf
(
"EnQueue:3 %s
\n
"
,
EnQueue
(
&
Q
,
3
)
?
"TURE"
:
"FALSE"
);
printf
(
"GetFront:%d %s
\n
"
,
value
,
GetFront
(
&
Q
,
&
value
)
?
"TURE"
:
"FALSE"
);
while
(
DeQueue
(
&
Q
,
&
value
))
{
printf
(
"DeQueue:%d
\n
"
,
value
);
}
printf
(
"GetFront: %s
\n
"
,
GetFront
(
&
Q
,
&
value
)
?
"TURE"
:
"FALSE"
);
free
(
Q
.
base
);
//释放申请的内存空间
}
\ No newline at end of file
includes/SeqQueue.h
0 → 100644
浏览文件 @
14253998
/*
* @Description: 顺序循环队列
* @Author: 大熊人
* @LastEditTime: 2020-11-08 18:28:38
*/
#define QUEUE_DATA_TYPE int
#define MAXSIZE 10
#define TRUE 1
#define FALSE 0
/* 顺序循环队列结构体 */
typedef
struct
SeqQueue
{
QUEUE_DATA_TYPE
*
base
;
int
front
;
//头指针
int
rear
;
//尾指针
}
SeqQueue
;
int
InitQueue
(
SeqQueue
*
Q
);
int
IsEmpty
(
SeqQueue
*
Q
);
int
IsFull
(
SeqQueue
*
Q
);
int
EnQueue
(
SeqQueue
*
Q
,
QUEUE_DATA_TYPE
X
);
int
DeQueue
(
SeqQueue
*
Q
,
QUEUE_DATA_TYPE
*
X
);
int
GetFront
(
SeqQueue
*
Q
,
QUEUE_DATA_TYPE
*
X
);
int
QueueLength
(
SeqQueue
*
Q
);
void
TestSeqQueue
();
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录