#pragma once

class MyQueue
{
public:
MyQueue();
~MyQueue();
void Insert(int aValue);
int Top();
void Pop();
void PrintQueue();
void PrintHead(); private:
int GetIncreIndex(const int& aIndex); private:
int* m_pData;
int m_Length;
int m_Count;
int m_Head;
int m_Tail;
};
#include "MyQueue.h"
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h> MyQueue::MyQueue( void )
:m_pData(NULL)
, m_Length()
, m_Head()
, m_Tail()
, m_Count()
{
m_pData = (int*)malloc(sizeof(int)*m_Length);
memset(m_pData,,m_Length);
} void MyQueue::Insert( int aValue )
{
m_pData[m_Tail] = aValue;
m_Tail = (m_Tail+)%m_Length;
++m_Count; if (m_Count == m_Length-)
{
m_Length = m_Length << ;
m_pData = (int*)realloc(m_pData,sizeof(int)*m_Length);
}
} int MyQueue::Top()
{
return m_pData[m_Head];
} void MyQueue::Pop()
{
if (m_Count == )
{
printf("NoData\n");
return;
}
m_Head = (m_Head+)%m_Length;
--m_Count;
} MyQueue::~MyQueue()
{
delete []m_pData;
} void MyQueue::PrintQueue()
{
if (m_Count > )
{
int lTempIndex = m_Head;
do
{
printf("%d ", m_pData[lTempIndex]);
lTempIndex = GetIncreIndex(lTempIndex);
} while (lTempIndex != m_Tail);
} printf("\n");
} int MyQueue::GetIncreIndex( const int& aIndex )
{
return (aIndex+)%m_Length;
} void MyQueue::PrintHead()
{
if (m_Count==)
{
printf("NoData\n");
return;
}
printf("Head: %d\n",m_pData[m_Head]);
}

MyStack的更多相关文章

  1. 我的STL之旅 MyStack

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...

  2. 一起学 Java(三) 集合框架、数据结构、泛型

    一.Java 集合框架 集合框架是一个用来代表和操纵集合的统一架构.所有的集合框架都包含如下内容: 接口:是代表集合的抽象数据类型.接口允许集合独立操纵其代表的细节.在面向对象的语言,接口通常形成一个 ...

  3. 菜鸟学Struts2——Interceptors

    昨天学习Struts2的Convention plugin,今天利用Convention plugin进行Interceptor学习,虽然是使用Convention plugin进行零配置开发,这只是 ...

  4. 数据结构笔记--栈的总结及java数组实现简单栈结构

    杂谈"栈"结构: 栈(Stack)是一种插入删除操作都只能在一个位置上进表,这个位置位于表的末端,叫做栈顶(Top). 对栈的基本操作有push和pop,表示进栈和出栈.也就相当于 ...

  5. [LeetCode] Implement Stack using Queues 用队列来实现栈

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  6. Struts2 拦截器配置以及实现

    @(Java ThirdParty)[Struts|Interceptor] Struts2 拦截器配置以及实现 Struts2的拦截器应用于Action,可以在执行Action的方法之前,之后或者两 ...

  7. java合集框架第一天

    文章目录 1 collection接口 2  list接口 3 Iterator 4 Vertor 5  ArrayList 6 LinkedList 主体部分: (1)collection Java ...

  8. string stack操作要注重细节问题

    A string S consisting of N characters is considered to be properly nested if any of the following co ...

  9. BUG-FREE-For Dream

    一直直到bug-free.不能错任何一点. 思路不清晰:刷两天. 做错了,刷一天. 直到bug-free.高亮,标红. 185,OA(YAMAXUN)--- (1) findFirstDuplicat ...

随机推荐

  1. Laravel 5.5 使用 Jwt-Auth 实现 API 用户认证以及刷新访问令牌

    最近在做一个公司的项目,前端使用 Vue.js,后端使用 Laravel 构建 Api 服务,用户认证的包本来是想用 Laravel Passport 的,但是感觉有点麻烦,于是使用了 jwt-aut ...

  2. 成为Linux内核高手的四个方法

    首页 最新文章 资讯 程序员 设计 IT技术 创业 在国外 营销 趣文 特别分享 更多 > - Navigation -首页最新文章资讯程序员设计IT技术- Java & Android ...

  3. [Functional Programming] Arrow Functor with contramap

    What is Arrow Functor? Arrow is a Profunctor that lifts a function of type a -> b and allows for ...

  4. register_shutdown_function函数详解--脚本退出时执行回调函数

    register_shutdown_function — Register a function for execution on shutdown. ps:Registers a callback  ...

  5. performSelector 多个参数

    [self performSelector:@selector(callFooWithArray) withObject:[NSArray arrayWithObjects:@"first& ...

  6. MyBatis - (二) 一对一映射和一对多映射

    1. 一对一映射 例子表: 学生表 地址表 POJO类 public class Address { private Integer addrId; private String street; pr ...

  7. gzcms技术开发文档

    1.输出统一的json格式ajaxJSON.cs: 2.web.config注册html控件:3.gzcms.contrls开发控件库:4.form序列化提交$(this).serializeJson ...

  8. TCP连接的建立和断开

    1.TCP连接的建立            设主机B运行一个服务器进程,它先发出一个被动打开命令,告诉它的TCP要准备接收客户进程的连续请求,然后服务进程就处于听的状态.不断检测是否有客户进程发起连续 ...

  9. MVC 之 缓存机制(一)

    一.概述 缓存是将信息(数据或页面)放在内存中以避免频繁的数据库存储或执行整个页面的生命周期,直到缓存的信息过期或依赖变更才再次从数据库中读取数据或重新执行页面的生命周期.在系统优化过程中,缓存是比较 ...

  10. 使用SqlBulkCopy类实现导入excel表格

    前言: 上篇博客介绍了SqlBulkCopy类批量操作数据库的相关操作,最后提到了可以使用这个类实现excel文件导入数据库,接下来我做简单介绍. 首先说一下思路: 把excel中的数据读出来并放入到 ...