queue.cpp
来自「本程序在visual c++环境下实现二叉树的层次遍历.」· C++ 代码 · 共 49 行
CPP
49 行
// queue.cpp: implementation of the queue class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "queue.h"
#include "Tree.h"
#include "stdlib.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
queue::queue()
{
head = rear = NULL;
}
queue::~queue()
{
}
//向队列中添加新的元素。
void queue::Add_Queue( binode * element)
{
struct node * q;
q = (struct node *) malloc (sizeof(struct node));
q->item = element ;
q->next = NULL;
if(rear==NULL)
rear = q;
else
{
rear->next = q; /**/
rear = q;
}
if(head==NULL)
head = rear;
}
//从队列中删除元素
binode * queue::Del_Queue()
{
struct binode * q;
q = (struct binode *) malloc (sizeof(struct binode));
q = head->item;
head = head->next;
return q;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?