﻿//VC++ 2008
//Console Application

struct Row
{
    public: int Field1;
    public: int Field2;
    public: int Field3;
};



class List
{
    private: Row* m_Buffer;
    private: int m_Length;
    private: int m_Count;
    //________________________________________________________________________

    public: List(void)
    {
        this->m_Length = 1;
        this->m_Buffer = new Row[this->m_Length];
        this->m_Count = 0;
    }
    //________________________________________________________________________

    public: void Insert(const Row& value, int index)
    {
        //----- Clamp ...
        if (index < 0) index = 0;
        else if (index > this->m_Count) index = this->m_Count;
        //----- Expand ...
        if (this->m_Count >= this->m_Length)
        {
            int capacity = this->m_Length;
            this->m_Length *= 2;
            Row* newbuffer = new Row[this->m_Length];

            while (--capacity >= 0)
                newbuffer[capacity] = this->m_Buffer[capacity];

            delete[] this->m_Buffer;
            this->m_Buffer = newbuffer;
        }
        //----- Shift ...
        for (int i = this->m_Count; i > index; --i)
        {
            this->m_Buffer[i] = this->m_Buffer[i - 1];
        }
        //----- Set ...
        this->m_Buffer[index] = value;
        this->m_Count++;
    }
    //________________________________________________________________________

    public: void Add(const Row& value)
    {
        this->Insert(value, 0x7fffffff);
    }
    //________________________________________________________________________

    public: void RemoveAt(int index)
    {
        if (this->m_Count <= 0) return;
        //----- Clamp ...
        if (index < 0) index = 0;
        else if (index >= this->m_Count) index = this->m_Count - 1;
        //----- Shift ...
        while (++index < this->m_Count)
        {
            this->m_Buffer[index - 1] = this->m_Buffer[index];
        }
        //----- Set ...
        this->m_Count--;
    }
    //________________________________________________________________________

    public: int Count()
    {
        return this->m_Count;
    }
    //________________________________________________________________________

    public: Row& operator[](int index)
    {
        if (this->m_Count <= 0) return *((Row*)NULL);
        if (index < 0) index = 0;
        else if (index >= this->m_Count) index = this->m_Count - 1;

        return this->m_Buffer[index];
    }
    //________________________________________________________________________

    ~List(void)
    {
        this->m_Count = this->m_Length = 0;
        if (this->m_Buffer != NULL) delete[] this->m_Buffer;
        this->m_Buffer = NULL;
    }
    //________________________________________________________________________
};





void main()
{
    List* v = new List();
    Row r;

    r.Field1 = 14;
    v->Add(r);

    r = (*v)[0];
    r.Field2 = 114;
    (*v)[0] = r;

    //...

    int iField;
    cin >> iField;
    cout << "End";
}
