当前位置:   article > 正文

双向队列

双向队列

双向队列(deque)

故名思意,就是不论从那边看都是一个队列。(我觉得像是两个栈,栈底拼在一起),两端都能进行插入和删除。在这里插入图片描述
双向队列也是基于线性表的,因此数组和链表都可以实现它,在此我就仅用链表实现一下。

typedef int ELemType; //用int来模拟数据项类型

typedef struct Node//数据节点
{
   
	ELemType data;
	struct Node* pre;
	struct Node* next;
}*DuList;

typedef struct
{
   
	int size;
	DuList front;
	DuList back;
}Deque;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

大小

int Size_Deque(Deque* D)
{
   
	assert(D != NULL);
	return D->size;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

初始化

bool Init_Deque(Deque* D)
{
   
	assert(D != NULL);
	D->size = 0;
	D->front = NULL;
	D->back = NULL;
	return true;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

清空

bool Clear_Deque(Deque* D)
{
   
	assert(D != NULL);
	while (!IsEmpty_Deque(D))
	{
   
		Pop_Front_Deque(D)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/891757
推荐阅读
相关标签
  

闽ICP备14008679号