zoukankan
html css js c++ java
顺序队列基本操作
顺序队列基本操作
#include
"
stdafx.h
"
#include
"
stdio.h
"
#include
"
stdlib.h
"
#define
SMALL 1
#if
(SMALL)
#define
MAX 7
int
QueueData[MAX]
=
{
'
A
'
,
'
B
'
,
'
C
'
,
'
D
'
,
'
E
'
,
'
F
'
,
'
G
'
}
;
#else
#define
MAX 14
int
QueueData[MAX]
=
{
'
A
'
,
'
B
'
,
'
C
'
,
'
D
'
,
'
E
'
,
'
F
'
,
'
G
'
,
'
H
'
,
'
I
'
,
'
J
'
,
'
K
'
,
'
L
'
,
'
M
'
,
'
N
'
}
;
#endif
/**/
/*
顺序队列类型定义
*/
typedef
struct
{
int
data[MAX];
int
head;
int
tail;
}
sqQueue;
/**/
/*
链队列类型定义
*/
struct
LinkQueue
{
int
data;
struct
LinkQueue
*
link;
}
;
typedef
struct
LinkQueue lkQueue;
//
-----------------------------------------------------------------------------------------
/**/
/*
顺序队列基本操作函数定义部分
*/
//
顺序队列的初始化函数sqInitialize()
sqQueue
*
sq_Initialize()
{
sqQueue
*
p;
p
=
(sqQueue
*
)malloc(
sizeof
(sqQueue));
if
(p
==
NULL)
{
return
(NULL);
}
else
{
p
->
data[
0
]
=
0
;
p
->
head
=
0
;
p
->
tail
=
0
;
return
(p);
}
}
//
顺序队列的判空函数qIsEmpty()
int
qIsEmpty(sqQueue
*
queue)
{
if
(queue
->
head
==
queue
->
tail)
return
(
1
);
else
return
(
0
);
}
//
顺序队列的判满函数qIsFull()
int
qIsFull(sqQueue
*
queue)
{
if
(queue
->
head
==
MAX)
return
(
1
);
else
return
(
0
);
}
//
顺序队列的入队函数qInQueue()
int
qInQueue(sqQueue
*
queue,
int
data)
{
if
(queue
->
tail
==
MAX)
{
printf(
"
队列已满!\n
"
);
return
(
0
);
}
else
{
queue
->
data[queue
->
tail
++
]
=
data;
return
(
1
);
}
}
//
顺序队列的出队函数qOutQueue()
int
qOutQueue(sqQueue
*
queue,
int
*
p)
{
if
(queue
->
head
==
queue
->
tail)
{
printf(
"
队列已空!\n
"
);
return
(
0
);
}
else
{
*
p
=
queue
->
data[queue
->
head
++
];
return
(
1
);
}
}
//
顺序队列的数据入队操作函数qInputValue()
void
qInputValue(sqQueue
*
queue,
int
array[])
{
int
i
=
0
;
while
(qInQueue(queue,array[i]))
printf(
"
Queue[%d] = %c\t
"
,i,array[i
++
]);
}
//
顺序队列的数据出队操作函数qOutputValue()
void
qOutputValue(sqQueue
*
queue)
{
int
i,QueueData;
i
=
0
;
while
(qOutQueue(queue,
&
QueueData))
printf(
"
Queue[%d] = %c\t
"
,i
++
,QueueData);
printf(
"
\n
"
);
}
//
-----------------------------------------------------------------------------------------
/**/
/*
链式队列基本操作函数定义部分
*/
//
链式队列的初始化函数lk_Initialize()
lkQueue
*
lk_Initialize()
{
lkQueue
*
p;
p
=
(lkQueue
*
)malloc(
sizeof
(lkQueue));
if
(p
==
NULL)
{
return
(NULL);
}
else
{
p
->
data
=
0
;
p
->
link
=
NULL;
return
(p);
}
}
//
链式队列的入队函数lkInQueue()
//
注意:在入队时,参数是队尾指针,返回值也是队尾指针
lkQueue
*
lkInQueue(lkQueue
*
tail,
int
data)
{
lkQueue
*
p;
p
=
(lkQueue
*
)malloc(
sizeof
(lkQueue));
if
(p
==
NULL)
{
printf(
"
新增链式队列元素时内存溢出!\n
"
);
return
(tail);
}
else
{
p
->
data
=
data;
p
->
link
=
tail;
return
(p);
}
}
//
链式队列的出队函数lkInQueue()
//
注意:在出队时,参数是队首指针,返回值也是队首指针
lkQueue
*
lkOutQueue(lkQueue
*
head,
int
*
data)
{
*
p
=
head
->
data;
lkQueue
*
p;
p
=
(lkQueue
*
)malloc(
sizeof
(lkQueue));
if
(p
==
NULL)
{
printf(
"
创建链式队列时内存溢出!\n
"
);
return
(tail);
}
else
{
p
->
data
=
data;
p
->
link
=
tail;
return
(p);
}
}
//
-----------------------------------------------------------------------------------------
int
main(
int
argc,
char
*
argv[])
{
sqQueue
*
queue1;
lkQueue
**
lkHead,
**
lkTail;
queue1
=
sq_Initialize();
if
(queue1
==
NULL)
{
printf(
"
创建顺序队列时内存溢出!\n
"
);
return
0
;
}
else
{
printf(
"
\n顺序队列[入队]数据
\n
"
);
qInputValue(queue1,QueueData);
printf(
"
\n顺序队列[出队]数据
\n
"
);
qOutputValue(queue1);
}
printf(
"
\n运行完毕!\n
"
);
return
0
;
}
查看全文
相关阅读:
Mac下写博客工具ecto相关资料
重装MacOS
Mac下写博客工具MarsEdit相关资料
Mac下安装最新版本的Graphviz
什么是回归分析?
Mac 配置Charles抓https的包
Android sdk tool android 命令参数
判断某个端口被那个进程占用
[置顶] 微创新时代个人崛起的方法
xml获取配置DataTable
原文地址:https://www.cnblogs.com/powersun/p/972020.html
最新文章
Linux:读取文件,每行拆分,并比较拆分数组长度
Spark(五十三):Spark RPC初尝试使用
Spark(五十二):Spark Scheduler模块之DAGScheduler流程
Spark(五十一):Spark On YARN(Yarn-Cluster模式)启动流程源码分析(二)
在Windows系统下搭建Redis集群
Java-Maven(十):Maven 项目常用plugins
Java-Maven(九):Maven 项目pom文件引入工程根目录下lib文件夹下的jar包
JVM GC原理
Python之 Virtualenv简明教程
Flask之 安装与HelloWorld
热门文章
Django之 静态模板渲染
Django之 HelloWorld
Python 入门级报错处理
Css之 间距初始化
Python之 操作 MySQL 数据库
python之 自动补全 tab
zabbix之 orabbix模板监控oracle
网络之 Iptables总结
Golang 正则表达式Regex相关资料整理
VirtualBox VM启用3D加速
Copyright © 2011-2022 走看看