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 ...
随机推荐
- jQuery实现锚点跳转(就一行代码)
/* 锚点跳转 */ function anchor(p,fn) { $("html,body").animate({ scrollTop: $("#" + p ...
- git版本还原
本地还原 在确认需要进行版本还原以后, 打开GIT BASH 输入: git reset --hard ad76ebf5ba8fb12bc38300ee99db478b332c1f7b 此操作成功以后 ...
- 【Eclipse】Eclipse性能调优
Eclipse性能调优 eclipse 吃内存_百度搜索 eclipse 性能调优之内存分配 - Defonds 的专栏 - CSDN博客 优化JVM参数提高eclipse运行速度 - Java综合 ...
- mysql的水平拆分和垂直拆分 (转)
http://www.cnblogs.com/sns007/p/5790838.html 1,水平分割: 例:QQ的登录表.假设QQ的用户有100亿,如果只有一张表,每个用户登录的时候数据库都要从这1 ...
- Linq-插入insert
1.简单形式 说明:new一个对象,使用InsertOnSubmit方法将其加入到对应的集合中,使用SubmitChanges()提交到数据库. NorthwindDataContext db = n ...
- 调试工具DebugView
可以用来跟踪如下函数的输出: Win32 OutputDebugString Kernel-mode DbgPrint All kernel-mode variants of DbgPrint i ...
- Android Handler 消息处理使用
本文内容 环境 演示 Handler 消息处理 参考资料 Handler 有两个主要作用或者说是步骤:发送消息和处理消息.在新启动的线程中发送消息,在主线程中获取.并处理消息.Android 平台只允 ...
- Discuz常见小问题-如何禁止调整宽屏模式
在界面-界面设置中,可以勾选窄屏,不允许用户自由切换
- Reshaper cannot resolve symbol
问题 不知道出了什么问题,在代码视图发现有些关键词显示为红色,并且Reshaper提示消息为Reshaper cannot resolve symbol XXX ,但编辑不会报错. 虽然不影响使用,但 ...
- 从MyEclipse到IntelliJ IDEA ——让你脱键盘,全键盘操作
从MyEclipse到IntelliJ IDEA ——让你脱键盘,全键盘操作 从MyEclipse转战到IntelliJ IDEA的经历 我一个朋友写了一篇“从Eclipse到Android Stud ...