// #include "queue.h"
#include "stdio.h"
#include "malloc.h"
/**
* @brief 链式队列数据结构定义
*/
typedef struct QueueStruct
{
char *value;
struct QueueStruct *next;
} queueStruct;
queueStruct *head, *tail;
/**
* @brief 链式队列初始化
*/
void QueueInit()
{
head = tail = (queueStruct *)malloc(sizeof(queueStruct));
head->next = NULL;
tail->next = NULL;
}
/**
* @brief 入队操作
*
* @param value 传入一个字符串
*/
void Enqueue(char *value)
{
queueStruct *q = (queueStruct *)malloc(sizeof(queueStruct));
q->value = value;
q->next = NULL;
if ((head->next == NULL) && (tail->next == NULL))
{
tail->next = q;
}
head->next = q;
head = head->next;
}
/**
* @brief 出队操作
*
* @return char* 返回出队的字符串
*/
char *Dequeue()
{
char *str;
str = tail->next->value;
tail->next = tail->next->next;
return str;
}
/**
* @brief 判断是否队空
*
* @return unsigned char 1——队空 0——队里有数据
*/
unsigned char IsEmpty()
{
return (tail->next == NULL) ? 1 : 0;
}
/**
* @brief 打印队列内容
*/
void PrintQueue()
{
queueStruct *q = tail->next;
while (q != NULL)
{
puts(q->value);
q = q->next;
printf("\n");
}
}
int main()
{
char a[] = "asdas";
char b[] = "aqweqe";
char c[] = "2341321";
QueueInit();
Enqueue(a);
Enqueue(b);
Enqueue(c);
Dequeue();
printf("%d", IsEmpty());
Dequeue();
printf("%d", IsEmpty());
Dequeue();
printf("%d", IsEmpty());
return 0;
}
![](https://img-blog.csdnimg.cn/2f03ea6938b44b2b80320ba6f8f7d6a2.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAbGl1X2VuZG9uZw==,size_20,color_FFFFFF,t_70,g_se,x_16)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)