C队列实现:
#include <stdio.h>
//节点
struct Node{
int data;//节点数据
Node *next;//下一节点
};
//队列
struct Queue{
Node *front;//队头
Node *end;//队尾
};
//创建节点
struct Node* createNode(int _data){
//创建节点内存
struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = _data;//节点数据
newNode->next = NULL;//下一节点
return newNode;//返回节点
};
//创建队列
struct Queue* createQueue(){
//分配队列内存
struct Queue *newQueue = (struct Queue*)malloc(sizeof(struct Queue));
newQueue->front = newQueue->end = NULL;//默认队头队尾为空
return newQueue;//返回队列
};
//空队判断
bool isEmpty(struct Queue *q){
return q->front == NULL;
}
//取队头数据
int front(struct Queue *q){
if (isEmpty(q)) {
printf("队列为空");
本文详细介绍了如何在C语言和C++中实现队列,并提供了具体的调用示例,展示了C与C++两种语言在数据结构应用上的差异。
订阅专栏 解锁全文
690

被折叠的 条评论
为什么被折叠?



