没用过动态数组库。。干脆自己写个渣渣的动态数组类 实在想不到名字
#include <Iostream>
using namespace std;
class 动态数组
{
private:
int *m_pInt;
int m_iNum;
public:
void Add(int m_Value)
{
/* 如果已经有了就新开辟空间保存 没有的直接开辟 */
if (NULL == m_pInt)
{
m_pInt = new int[1];
m_pInt[0] = m_Value;
m_iNum++;
}
else
{
int *m_temp = new int[m_iNum + 1];
memcpy(m_temp, m_pInt, m_iNum * sizeof(int));
delete[]m_pInt;
m_pInt = m_temp;
m_pInt[m_iNum] = m_Value;
m_iNum++;
}
}
int *getPointer()
{
return this->m_pInt;
}
int getNumber()
{
return this->m_iNum;
}
void operator= (const 动态数组&A)
{
//cout << "=重载" << endl;
/* 如果已经有数据了就删除再开辟 没有直接开辟复制 */
if (NULL == this->m_pInt)
{
this->m_pInt = new int[A.m_iNum];
memcpy(this->m_pInt, A.m_pInt, sizeof(int) * A.m_iNum);
this->m_iNum = A.m_iNum;
}