template<typename ElemType>
class SqQueue
{
protected:
int count;
int front,rear;
int maxSize;
ElemType *elem;
public:
SqQueue(){}
SqQueue(int size);
virtual ~SqQueue();
int Length() const;
bool Empty() const;
void Clear();
void Traverse(void (*visit)(const ElemType &))const;
bool OutQueue(ElemType &e);
bool GetHead(ElemType &e) const;
bool InQueue(const ElemType &e);
SqQueue(const SqQueue<ElemType> &copy);
SqQueue<ElemType> &operator =(const SqQueue<ElemType> &copy);
};
template<typename ElemType>
//构造函数
SqQueue<ElemType>::SqQueue(int size)
{
maxSize=size;
elem=new ElemType[maxSize];
rear=front=;
count=;
}
template<typename ElemType>
//虚虚构函数
SqQueue<ElemType>::~SqQueue()
{
delete []elem;
}
template<typename ElemType>
//SqQueue长度
int SqQueue<ElemType>::Length() const
{
return count;
}
template<typename ElemType>
//判断空队列
bool SqQueue<ElemType>::Empty() const
{
return count==;
}
template<typename ElemType>
//清空队列
void SqQueue<ElemType>:: Clear()
{
rear=front=;
count=;
}
template<typename ElemType>
//遍历队列
void SqQueue<ElemType>::Traverse(void(*visit)(const ElemType & ))const
{
for(int pos=front;pos!=rear;pos=(pos+)%maxSize)
(*visit)(elem[pos]); }
template<typename ElemType>
//队首出
bool SqQueue<ElemType>::OutQueue(ElemType &e)
{
if(!Empty())
{
e=elem[front];
front=(front+)%maxSize;
count--;
return true;
}
else return false;
}
template<typename ElemType>
//加入新队尾
bool SqQueue<ElemType>::InQueue(const ElemType &e)
{
if(count==maxSize)
return false;
else
{
elem[rear]=e;
rear=(rear+)%maxSize;
count++;
return true;
} }
template<typename ElemType>
//复制构造
SqQueue<ElemType>::SqQueue(const SqQueue<ElemType> &copy)
{
maxSize=copy.maxSize;
elem=new ElemType[maxSize];
front=copy.front;
rear=copy.rear;
count=copy.count;
for(int pos=front;pos!=rear;pos=(pos+)%maxSize)
elem[pos]=copy.elem[pos];
}
template<typename ElemType>
//重载=operator
SqQueue<ElemType> &SqQueue<ElemType>::operator=(const SqQueue<ElemType> &copy)
{
if(&copy!=this)
{
maxSize=copy.maxSize;
delete []elem;
elem=new SqQueue<ElemType>[maxSize];
count=copy.count;
front=copy.front;
rear=copy.rear;
for(int pos=front;pos!=rear;pos=(pos+)%maxSize)
elem[pos]=copy.elem[pos];
return *this;
} }

SqQueue(环状队列(顺序表结构))的更多相关文章

  1. C语言 线性表 顺序表结构 实现

    一个能够自动扩容的顺序表 ArrList (GCC编译). #include <stdio.h> #include <stdlib.h> #include <string ...

  2. c语言-顺序表

    在数据结构中包含两种,一种线性结构(包括顺序表,链表,栈,队列),一种非线性结构(树,图), 顺序表,其实就是在内存动态数组,Java中的ArrayList就是一个典型的顺序表,它在顺序表的基础上增加 ...

  3. 顺序表及其多种实现方式 --- C/C++

    所谓顺序表,即线性表的顺序存储结构.下面给出的是数据结构---线性表的定义. ADT List{ 数据对象: 线性表的数据对象的集合为{a1,a2,a3,...,an},每个元素的类型为ElemTyp ...

  4. C++中如何建立一个顺序表

    准备数据 #define MAXLEN 100 //定义顺序表的最大长度 struct DATA { char key[10]; //结点的关键字 char name[20]; int age; }; ...

  5. 顺序表--MyArrayList的实现

    实现的MyArrayList实为顺序表结构,其中要实现Iterable时必须在内部实现Iterator,即为该表的迭代器. public class MyArrayList<AntType> ...

  6. C#顺序表 & 单向链表(无头)

    C# 顺序表 非常标准的顺序表结构,等同于C#中的List<T>,但是List<T>在排错查询和数据结构替换上存在缺陷,一些情况会考虑使用自己定义的数据结构 1.优化方向 下表 ...

  7. python基础下的数据结构与算法之顺序表

    一.什么是顺序表: 线性表的两种基本的实现模型: 1.将表中元素顺序地存放在一大块连续的存储区里,这样实现的表称为顺序表(或连续表).在这种实现中,元素间的顺序关系由它们的存储顺序自然表示. 2.将表 ...

  8. Java算法 -- 顺序表

    顺序表结构定义:就是按照顺序存储方式存储的线性表 1.定义一个顺序表的基本数据: static final int MAXLEN = 100; Class Student{ private Strin ...

  9. C语言顺序表

    顺序表结构可设为一个数组和一个指向尾部的变量,数组用来存放元素,指向尾部的变量在插入元素的时候加一,删除元素的时候减一,始终指向尾部. typedef int elemtype; typedef st ...

随机推荐

  1. 导出CSV表格数据

    <?php class Csv{ //导出csv文件 public function put_csv($list,$title){ $file_name="CSV".date ...

  2. 国内互联网公司github网址

    -----------------------------------------------------推荐技术------------------------------------------- ...

  3. JAVA基础——面向对象三大特性:封装、继承、多态

    JAVA面向对象三大特性详解 一.封装 1.概念: 将类的某些信息隐藏在类内部,不允许外部程序直接访问,而是通过该类提供的方法来实现对隐藏信息的操作和访问. 2.好处: 只能通过规定的方法访问数据. ...

  4. 邪恶改装2:用单片机实现一次简单的wifi密码欺骗

    0×00 前言 前段时间用TPYBoard v202 做了一个简单的WIFI干扰攻击器(ps :没有看过的小伙伴,可以看一下:http://www.freebuf.com/column/136985. ...

  5. Azure SQL Database (23) Azure SQL Database Dynamic Data Masking动态数据掩码

    <Windows Azure Platform 系列文章目录> 我们在使用关系型数据的时候,有时候希望: - 管理员admin,可以查看到所有的数据 - 普通用户,某些敏感字段,比如信用卡 ...

  6. h5 新增特性用法---持续更新

    1.dataset <div class="box" data-title1="自定义属性" data-age="18" data-m ...

  7. 原生js表单序列化----- FormData

    <style type="text/css"> .progress{ height: 10px; width: 600px; border: 1px solid red ...

  8. windows安装程序无法将windows配置为在此计算机的硬件上运行

    关于装windows系统时,出现一些安装中断的处理 该方法适用于 windows安装程序无法将windows配置为在此计算机的硬件上运行 计算机意外地重新启动或遇到错误. Windows 安装无法继续 ...

  9. Bootstrap提示框

    前面的话 提示框是一个比较常见的功能,一般来说是鼠标移动到特定元素上时,显示相关的提示语.本文将详细介绍Bootstrap提示框 基本用法 Bootstrap框架中的提示框,结构非常简单,常常使用的是 ...

  10. jQuery手风琴的制作!!

    jQuery手风琴的制作 首先我们先来做一个简单的jQuery的效果图 效果图 如下: css代码 如下: <style type="text/css" media=&quo ...