网站建设一般需要几个步骤,网站怎么做多语言展示,wordpress 分类主题,海口网站建设服务目录 创建
初始化
销毁
头插
尾删
取出头
取出尾
数字个数
判空 队列的性质与特征
性质#xff1a;一种先进先出的线性表
特征#xff1a;FIFO#xff08;先进先出#xff09;
实现#xff1a;用数组和链表的都可以
例子#xff1a;在生产者消费者模型用到了…目录 创建
初始化
销毁
头插
尾删
取出头
取出尾
数字个数
判空 队列的性质与特征
性质一种先进先出的线性表
特征FIFO先进先出
实现用数组和链表的都可以
例子在生产者消费者模型用到了循环链表
模型未来曲风队列是满的还是不满的我们多加一个空间保证rear1是front 创建
typedef struct Queue//避免老是传二级指针
{QNode* phead;QNode* tail;int size;}Queue;typedef struct QNode
{struct QNode* next;DataType val;
}QNode;
初始化
void QueueInit(Queue* p)
{assert(p);p-phead p-tailNULL;p-size 0;
}
销毁
void QueueDestroy(Queue* p)
{assert(p);QNode* cur p-phead;while (cur){free(cur);cur cur-next;}QueueInit(p);
}
头插
void QPush(Queue* p, DataType x)//插入先创建空间
{assert(p);QNode* newNode (QNode*)malloc(sizeof(QNode));if (newNode NULL){printf(malloc failed);return;}newNode-next NULL;newNode-val x;if (p-phead NULL){p-phead p-tail newNode;}else{p-tail-next newNode; p-tail newNode;}p-size;
}尾删
void Qpop(Queue* p)
{assert(p);assert(p-size);if (p-phead-next NULL){free(p-phead);p-phead p-tail NULL;}else{QNode* next p-phead-next;free(p-phead);p-phead next;}p-size--;
}
取出头
DataType QueueFront(Queue* p)
{assert(p);assert(p-phead);return p-phead-val;
}
取出尾
DataType QueueBack(Queue* p)
{assert(p);assert(p-tail);return p-tail-val;
}
数字个数
int QSize(Queue* p)
{assert(p);return p-size;
}
判空
bool QueueEmpty(Queue* p)
{assert(p);if (p-size 0)return true;elsereturn false;
}