数据结构_队列

队列是一种有序的线性表,队列的两端分别称为队首和队尾。队列只允许在队尾进行插入操作,在队首进行删除操作。

插入元素称为入队,删除元素称为出队。        队列常用链表或数组来实现。



#include <iostream>
#include <cstdlib>
using namespace std;

#define max 1000

//队列定义
struct element{
	int key;
}; 

element queue[max];
int rear = 0;
int front = 0;

//判断队列是否为空
bool is_empty()
{
	return front == rear;
} 

//判断队列是否已满
bool is_full()
{
	return rear == max;
} 

//入队操作
void push(element item)
{
	if (rear == max)
		exit(1);
	queue[rear++] = item;
} 

//出队(删除)操作
void pop()
{
	if (front == rear)
		exit(1);
	front ++ ;
} 

//读取队首元素
element front1()
{
	if (front == rear)
		exit(1);
	return queue[front];
} 

int main()
{
	
	return 0;
}


原文地址:https://www.cnblogs.com/Tovi/p/6194871.html