#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. 定时删除日志文件---linux定时清理日志

    linux是一个很能自动产生文件的系统,日志.邮件.备份等.虽然现在硬盘廉价,我们可以有很多硬盘空间供这些文件浪费,让系统定时清理一些不需要的文件很有一种爽快的事情.不用你去每天惦记着是否需要清理日志 ...

  2. protobuf-c的学习总结

    1.前言 项目中用到protobuf-c进行数据序列化,好处在于后期程序扩展性非常好,只需要改动proto的定义就可以保持兼容,非常的灵活方便.关于protobuf-c的详细介绍可以参考google官 ...

  3. unity3d Player Settings 中的Stripping Level(剥离等级)对应每个等级具体剥离了哪些库

    http://docs.unity3d.com/410/Documentation/ScriptReference/MonoCompatibility.html

  4. C 语言宏定义

    C 语言宏定义1.例子如下: #define PRINT_STR(s) printf("%s",s.c_str()) string str = "abcd"; ...

  5. Rainmeter 一部分 语法 中文教程

    ;Meter基本元素示例:;如果是[MeterStyle]表示Meter的公共Style,类似CSS的意义!!!;颜色可以使用网页的颜色定义方式,如半透明黄色:255.255.0.128=FFFF00 ...

  6. ThinkPHP3.2多域名 Virtual .htaccess 匹配 RewriteCond %{HTTP_HOST}

    <Files *> Options -Indexes </Files> <IfModule mod_headers.c> <FilesMatch " ...

  7. Skyline开发2-第一个程序

    来试试Skyline的Hello World.使用的工具是VS2017+Skyline6.5 加载组件 在工具箱右键新建skyline选项卡,在skyline选项卡上右键选择项,在弹出的"选 ...

  8. 【转】使用 Android 的日志工具LogCat

    Android中的日志工具类是 Log(android.util.Log),这个类中提供了如下几个方法来供我们打印日志. 1.    Log.v() 这个方法用于打印那些最为琐碎的,意义最小的日志信息 ...

  9. VCAP5-DCA – What’s new?

    see also: 韩国人的教材:http://ddii.pe.kr/ Section 1.1 – Implement and Manage complex storage Determine use ...

  10. django之创建第5个项目-条件语句

    1.index <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...