SeqQueue.h

#define QueueSize 100
typedef char DataType; class SeqQueue
{
public:
DataType data[QueueSize];
int front;
int rear; void Initial();
bool IsEmpty();
bool IsFull();
void EnQueue(DataType temp);
DataType DeQueue();
DataType Front();
};
SeqQueue.cpp
#include "SeqQueue.h"
#include <iostream>
using namespace std; void SeqQueue::Initial()
{
rear = front = 0;
} bool SeqQueue::IsEmpty()
{
return rear == front;
} bool SeqQueue::IsFull()
{
return rear - front == QueueSize - 1;
} void SeqQueue::EnQueue(DataType temp)
{
if(IsFull())
cout<< "队??列?D已??满??" <<endl;
else
{
data[rear] = temp;
rear++;
}
}
DataType SeqQueue::DeQueue()
{
if(IsEmpty())
{
cout<< "队??列?D为a空?" <<endl;
}
else
{
DataType temp;
temp = data[front];
front++;
return temp;
}
}
DataType SeqQueue::Front()
{
if(IsEmpty())
{
cout<< "队??列?D为a空?" <<endl;
}
else
{
DataType temp;
temp = data[front];
return temp;
}
}

  

 LinkQueue.h
typedef char DataType;
typedef struct node
{
DataType data;
node* next;
}Node;
class LinkQueue
{
public:
Node* front;
Node* rear; void Initial();
bool IsEmpty();
void EnQueue(DataType temp);
DataType DeQueue();
DataType Front();
};

  

LinkQueue.cpp
#include "LinkQueue.h"
#include <iostream>
using namespace std; void LinkQueue::Initial()
{
front = rear = NULL;
}
bool LinkQueue::IsEmpty()
{
return front == NULL;
} void LinkQueue::EnQueue(DataType temp)
{
Node* tempnode = (Node*)malloc( sizeof(Node));
tempnode->data = temp;
tempnode->next = NULL; if(IsEmpty())
{
front = rear = tempnode;
}
else
{
rear->next = tempnode;
rear = tempnode;
}
} DataType LinkQueue::DeQueue()
{
if(IsEmpty())
{
cout<< "链???队??列?D为a空?" ;
}
else
{
Node * tempnode = (Node*)malloc( sizeof(Node));
tempnode = front;
DataType temp;
temp = tempnode->data;
front = front->next;
if(rear==tempnode)
rear= NULL;
free(tempnode);
return temp;
}
}
DataType LinkQueue::Front()
{
if(IsEmpty())
{
cout<< "链???队??列?D为a空?" ;
}
else
return front->data;
}

  

main.cpp
#include <iostream>
#include "SeqQueue.h"
#include "LinkQueue.h"
using namespace std; int main()
{
SeqQueue mySeqQueue;
mySeqQueue.Initial();
mySeqQueue.EnQueue( 'a');
cout<<mySeqQueue.Front();
mySeqQueue.EnQueue( 'b');
mySeqQueue.EnQueue( 'c');
cout<<mySeqQueue.DeQueue();
cout<<mySeqQueue.DeQueue();
cout<<mySeqQueue.DeQueue();
mySeqQueue.DeQueue(); LinkQueue myLinkQueue;
myLinkQueue.Initial();
myLinkQueue.EnQueue( 'a');
myLinkQueue.EnQueue( 'b');
myLinkQueue.EnQueue( 'c');
cout<<myLinkQueue.DeQueue();
cout<<myLinkQueue.DeQueue();
cout<<myLinkQueue.DeQueue();
myLinkQueue.DeQueue();
return 0;
}

  

数据结构自己实现——queue的更多相关文章

  1. Python与数据结构[2] -> 队列/Queue[0] -> 数组队列的 Python 实现

    队列 / Queue 数组队列 数组队列是队列基于数组的一种实现,其实现类似于数组栈,是一种FIFO的线性数据结构. Queue: <--| 1 | 2 | 3 | 4 | 5 |<-- ...

  2. 第二十四篇 玩转数据结构——队列(Queue)

          1.. 队列基础 队列也是一种线性结构: 相比数组,队列所对应的操作数是队列的子集: 队列只允许从一端(队尾)添加元素,从另一端(队首)取出元素: 队列的形象化描述如下图: 队列是一种先进 ...

  3. 数据结构-Stack和Queue

    实现: #include "c2_list.h" template <typename object> class Stack{ public: bool isEmpt ...

  4. Python数据结构应用2——Queue

    Reference: Problem Solving with Algorithms and Data Structures, Release 3.0 队列 Queue 建立 class Queue: ...

  5. 自己实现数据结构系列四---Queue

    一.代码部分 1.定义接口: public interface Queue<E> { void enqueue(E e); E dequeue(); E getFront(); int g ...

  6. python 数据结构 队列(queue)

    如需转发,请注明出处:小婷儿的python https://www.cnblogs.com/xxtalhr/p/10293817.html 欢迎关注小婷儿的博客: 有问题请在博客下留言或加作者微信:t ...

  7. 算法与数据结构基础 - 队列(Queue)

    队列基础 队列具有“先进先出”的特点,用这个特点我们可以用它来处理时间序列相关或先后次序相关的问题,例如 LeetCode题目 933. Number of Recent Calls,时间复杂度O(1 ...

  8. 数据结构:队列queue 函数push() pop size empty front back

    队列queue: push() pop() size() empty() front() back() push()  队列中由于是先进先出,push即在队尾插入一个元素,如:可以输出:Hello W ...

  9. 数据结构之队列(queue)

    队列介绍 1.队列是一个有序列表,可以用数组或是链表来实现. 2.遵循先入先出的原则.即:先存入队列的数据,要先取出.后存入的要后取出. 应用场景 比如某某银行叫号系统: 数组模拟队列 队列本身是有序 ...

  10. 数据结构与算法-queue

    队列和stack类似,stack是先进后出,而queue的先进先出,也是一种特殊的线性表 基本概念 概念 队列是一种特殊的线性表 队列仅在线性表的两端进行操作 队头(Front):取出数据元素的一端 ...

随机推荐

  1. CentOS7下systemd

    配置文件: /usr/lib/systemd/system:每个服务最主要的启动脚本设置,类似于之前的/etc/init.d/ /run/systemd/system:系统执行过程中所产生的服务脚本, ...

  2. matlplotlib根据函数画出图形

    根据函数画出函数的轨迹 import matht = np.linspace(0, math.pi, 1000)x = np.sin(t)y = np.cos(t) + np.power(x, 2.0 ...

  3. 【Linux】开放指定端口设置

    这里以开放tomcat的8080端口为例 1.开放Linux的8080端口 vi /etc/sysconfig/iptables 进入编辑页面,在指定位置新增以下配置 -A INPUT -m stat ...

  4. asp发送短信验证码 pst方式

    <script language="jscript" runat="server">  Array.prototype.get = function ...

  5. LeetCode(155) Min Stack

    题目 Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. ...

  6. AD采样求平均STM32实现

    iADC_read(, &u16NTC_1_Sample_Val_ARR[]); == ui8FirstSampleFlag) { ; i<; i++) { u16NTC_1_Sampl ...

  7. The 2018 ACM-ICPC China JiangSu Provincial Programming Contest I. T-shirt

    JSZKC is going to spend his vacation! His vacation has N days. Each day, he can choose a T-shirt to ...

  8. 在终端更改MAC的MySQL的root密码

  9. CodeForces 392C Yet Another Number Sequence 矩阵快速幂

    题意: \(F_n\)为斐波那契数列,\(F_1=1,F_2=2\). 给定一个\(k\),定义数列\(A_i=F_i \cdot i^k\). 求\(A_1+A_2+ \cdots + A_n\). ...

  10. $.each 用break 好像不太灵啊

    for(var i=0;i<obj.length;i++) {                                       if (i < 5) {             ...