#include <iostream>
using namespace std;
class Vector
{
private:
int *pHead;
int *pCurrent_head;
int *pCurrent_tail;
int *pTail;
int iCurrent_size;
void Resize()
{
int *pDelete = pHead;
int *pNew_current_head;
int *pNew_current_tail;
iCurrent_size *= 2;
int *pNew_size = new int[iCurrent_size];
pHead = pNew_size;
pNew_current_head = pHead + 4;
pNew_current_tail = pNew_current_head;
while(pCurrent_head != pCurrent_tail)
{
*pNew_current_tail = *pCurrent_head;
pCurrent_head++;
pNew_current_tail++;
}
pCurrent_head = pNew_current_head;
pCurrent_tail = pNew_current_tail;
pTail = pHead + iCurrent_size;
delete pDelete;
}
public:
Vector()
{
iCurrent_size = 8;
pHead = new int[iCurrent_size];
pCurrent_head = pHead + (iCurrent_size / 2);
pCurrent_tail = pCurrent_head;
pTail = pHead + iCurrent_size;
}
void Print()
{
int *pPrint = pCurrent_head;
while(pPrint != pCurrent_tail)
{
cout<<*pPrint<<" ";
pPrint++;
}
cout<<endl;
}
void push_front(const int iValue)
{
if(pCurrent_head != pHead)
{
*pCurrent_head = iValue;
--pCurrent_head;
}
else
{
Resize();
*pCurrent_head = iValue;
--pCurrent_head;
}
}
void push_back(const int iValue)
{
if(pCurrent_tail != pTail)
{
*pCurrent_tail = iValue;
pCurrent_tail++;
}
else
{
Resize();
*pCurrent_tail = iValue;
pCurrent_tail++;
}
}
void pop_front()
{
if(pCurrent_head != pCurrent_tail)
{
pCurrent_head++;
}
else
{
cout<<"zhi xing le !"<<endl;
exit(1);
}
}
void pop_back()
{
if(pCurrent_head != pCurrent_tail)
{
pCurrent_tail--;
}
else
{
cout<<" zhe xing le !"<<endl;
return;
}
}
void Insert(int *pPosition, const int iValue)
{
if((pPosition < pCurrent_head) || (pPosition > pCurrent_tail))
{
return ;
}
else
{
if((pCurrent_head == pCurrent_tail) && (pPosition == pCurrent_head))
{
*pPosition = iValue;
--pCurrent_head;
++pCurrent_tail;
}
else if( pCurrent_head > pHead)
{
int *pMove_tail = pCurrent_head;
int *pMove_head = pMove_tail - 1;
while(pMove_head != pPosition)
{
*pMove_head = *pMove_tail;
pMove_head++;
pMove_tail++;
}
*pMove_head = *pMove_tail;
*pPosition = iValue;
}
else if(pCurrent_tail < pTail)
{
int *pMove_head = pCurrent_tail;
int *pMove_tail = pMove_head + 1;
while(pMove_head != pPosition)
{
*pMove_tail = *pMove_head;
pMove_head--;
pMove_tail--;
}
*pMove_tail = *pMove_head;
*pPosition = iValue;
}
else
{
return ;
}
}
}
int size()const
{
int iSize = 0;
int *pSize = pCurrent_head;
while(pSize != pCurrent_tail)
{
iSize++;
pSize++;
}
return iSize;
}
~Vector()
{
delete pHead;
}
};
int main()
{
/*Vector vec;
for(int i = 0; i < 15; i++)
vec.push_back(i);
int iSize = vec.size();
cout<<iSize<<endl;
cout<<"ge kai"<<endl;
vec.Print();*/
return 0;
}