const int ARRAY_GROWUP = 10;
struct ArrayStruct
{
int iMaxCount;
int iCurCount;
int *pHead;
};
//初始化
ArrayStruct *Array_Init(int iStartCount)
{
if(iStartCount <= 0)
return NULL;
ArrayStruct *pReturn;
pReturn = new ArrayStruct;
if(pReturn == NULL)
return NULL;
pReturn->pHead = new int[iStartCount];
if(pReturn->pHead == NULL)
return NULL;
pReturn->iMaxCount = iStartCount;
pReturn->iCurCount = 0;
return pReturn;
}
//插入元素
bool Array_AddElement(ArrayStruct *pArray,const int iAppendElement)
{
if(pArray == NULL)
return false;
if(pArray->iCurCount == pArray->iMaxCount)
{
//增加内存
int *Temp = new int[(pArray->iMaxCount + ARRAY_GROWUP)];
for(int i = 0;i<pArray->iCurCount;i++)
{
Temp[i] = pArray->pHead[i];
}
delete []pArray->pHead;
pArray->pHead = Temp;
pArray->iMaxCount = pArray->iMaxCount + ARRAY_GROWUP;
}
pArray->pHead[pArray->iCurCount] = iAppendElement;
pArray->iCurCount++;
return true;
}
//删除元素
bool Array_RemoveElement(ArrayStruct *pArray,const int iRemoveIndex)
{
if(pArray == NULL)
return false;
if(iRemoveIndex > pArray->iCurCount)
return false;
for(int i = iRemoveIndex-1;i<=pArray->iCurCount;i++)
{
pArray->pHead[i] = pArray->pHead[i+1];
}
pArray->iCurCount--;
return true;
}
//获取元素
bool Array_GetElement(const ArrayStruct *pArray,const int iIndex,int &iReturn)
{
cout<<pArray->iCurCount<<endl;
if(pArray == NULL)
return false;
if(iIndex > pArray->iCurCount)
return false;
iReturn = pArray->pHead[iIndex];
return true;
}
//删除动态数组
void Array_Release(ArrayStruct *pArray)
{
if(pArray == NULL)
return;
delete []pArray->pHead;
pArray->pHead = NULL;
pArray->iMaxCount = 0;
pArray->iCurCount = 0;
pArray = NULL;
struct ArrayStruct
{
int iMaxCount;
int iCurCount;
int *pHead;
};
//初始化
ArrayStruct *Array_Init(int iStartCount)
{
if(iStartCount <= 0)
return NULL;
ArrayStruct *pReturn;
pReturn = new ArrayStruct;
if(pReturn == NULL)
return NULL;
pReturn->pHead = new int[iStartCount];
if(pReturn->pHead == NULL)
return NULL;
pReturn->iMaxCount = iStartCount;
pReturn->iCurCount = 0;
return pReturn;
}
//插入元素
bool Array_AddElement(ArrayStruct *pArray,const int iAppendElement)
{
if(pArray == NULL)
return false;
if(pArray->iCurCount == pArray->iMaxCount)
{
//增加内存
int *Temp = new int[(pArray->iMaxCount + ARRAY_GROWUP)];
for(int i = 0;i<pArray->iCurCount;i++)
{
Temp[i] = pArray->pHead[i];
}
delete []pArray->pHead;
pArray->pHead = Temp;
pArray->iMaxCount = pArray->iMaxCount + ARRAY_GROWUP;
}
pArray->pHead[pArray->iCurCount] = iAppendElement;
pArray->iCurCount++;
return true;
}
//删除元素
bool Array_RemoveElement(ArrayStruct *pArray,const int iRemoveIndex)
{
if(pArray == NULL)
return false;
if(iRemoveIndex > pArray->iCurCount)
return false;
for(int i = iRemoveIndex-1;i<=pArray->iCurCount;i++)
{
pArray->pHead[i] = pArray->pHead[i+1];
}
pArray->iCurCount--;
return true;
}
//获取元素
bool Array_GetElement(const ArrayStruct *pArray,const int iIndex,int &iReturn)
{
cout<<pArray->iCurCount<<endl;
if(pArray == NULL)
return false;
if(iIndex > pArray->iCurCount)
return false;
iReturn = pArray->pHead[iIndex];
return true;
}
//删除动态数组
void Array_Release(ArrayStruct *pArray)
{
if(pArray == NULL)
return;
delete []pArray->pHead;
pArray->pHead = NULL;
pArray->iMaxCount = 0;
pArray->iCurCount = 0;
pArray = NULL;
}