MyStack
#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的更多相关文章
- 我的STL之旅 MyStack
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...
- 一起学 Java(三) 集合框架、数据结构、泛型
一.Java 集合框架 集合框架是一个用来代表和操纵集合的统一架构.所有的集合框架都包含如下内容: 接口:是代表集合的抽象数据类型.接口允许集合独立操纵其代表的细节.在面向对象的语言,接口通常形成一个 ...
- 菜鸟学Struts2——Interceptors
昨天学习Struts2的Convention plugin,今天利用Convention plugin进行Interceptor学习,虽然是使用Convention plugin进行零配置开发,这只是 ...
- 数据结构笔记--栈的总结及java数组实现简单栈结构
杂谈"栈"结构: 栈(Stack)是一种插入删除操作都只能在一个位置上进表,这个位置位于表的末端,叫做栈顶(Top). 对栈的基本操作有push和pop,表示进栈和出栈.也就相当于 ...
- [LeetCode] Implement Stack using Queues 用队列来实现栈
Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...
- Struts2 拦截器配置以及实现
@(Java ThirdParty)[Struts|Interceptor] Struts2 拦截器配置以及实现 Struts2的拦截器应用于Action,可以在执行Action的方法之前,之后或者两 ...
- java合集框架第一天
文章目录 1 collection接口 2 list接口 3 Iterator 4 Vertor 5 ArrayList 6 LinkedList 主体部分: (1)collection Java ...
- string stack操作要注重细节问题
A string S consisting of N characters is considered to be properly nested if any of the following co ...
- BUG-FREE-For Dream
一直直到bug-free.不能错任何一点. 思路不清晰:刷两天. 做错了,刷一天. 直到bug-free.高亮,标红. 185,OA(YAMAXUN)--- (1) findFirstDuplicat ...
随机推荐
- 利用blob对象实现粘贴图片
blob的一个常用应用场景,就是获取剪切板上的数据来进行粘贴的操作.例如通过QQ截图后,需要在网页上进行粘贴操作. 粘贴图片我们需要解决下面几个问题 1.监听用户的粘贴操作 2.获取到剪切板上的数据 ...
- Eclipse CDT 插件列表
http://www.bestplugins.com/software/eclipse-c-plugin.html
- JAVA基础编程50题(4-6题)具体解释
一.描写叙述 1.将一个正整数分解质因数.比如:输入90,打印出90=2*3*3*5. 程序分析:对n进行分解质因数,应先找到一个最小的质数k,然后按下述步骤完毕: (1)假设这个质数恰等于n,则说明 ...
- .NET 服务器定位模式(Service Locator Pattern)——Common Service Locator
本文内容 场景 目标 解决方案 实现细节 思考 相关模式 更多信息 参考资料 Common Service Locator 代码很简单,它一般不会单独使用,而是作为一个单件模式,与像 .net Uni ...
- Groovy 与 Python 的差异【翻译】
本文内容 General 一般 Lists 列表 Maps 映射 Ranges/Slices 范围/片段 Object access 对象访问 参考资料 Groovy 是一种基于 JVM 的敏捷开发语 ...
- 造轮子 | 怎样设计一个面向协议的 iOS 网络请求库
近期开源了一个面向协议设计的网络请求库 MBNetwork,基于 Alamofire 和 ObjectMapper 实现,目的是简化业务层的网络请求操作. 须要干些啥 对于大部分 App 而言,业务层 ...
- Android 之 WebView开发问题及优化
WebView 在现在的项目中使用的频率应该还是非常高的,WebView 主要用来加载一些容易改变的频繁交互的应用App.目前 HTML5 是一种趋势.在开发中会遇到一些开发问题及优化问题,如下所记. ...
- .net部署时常见问题
站点提示“不允许的父路径”怎么办 error: 40 - Could not open a connection to SQL Server解决办法 无法识别的属性“targetFramework”. ...
- 【树莓派】使用xdrp远程登录树莓派的图形界面
之前采用了vnc方式方式的树莓派,但是配置还有点步骤,刚才看了一下,试验了一下xrdp,直接很简单就好了. 树莓派DIY笔记之前有介绍过用VNC连接到树莓派的方法.在Windows下,当然还是自带的远 ...
- 第八周(3) Word2007样式
第八周(3) Word2007样式 教学时间 2013-4-19 教学课时 2 教案序号 23 教学目标 1.掌握样式的概念2.能够熟练地创建样式.修改样式的格式,使用样式3.熟练利用样式格式化文档 ...