#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]);
}
04-28 12:44