Stack Handmade Auto Resize

#include<iostream>
using namespace std;
int s = 1, i;
int *a = new int[1];
int t = -1;
void rsize(int b)
{
    cout << "Old Size :: " << s << endl;
    s *= 2;
    int *na = new int[s];
    for(i=0;i<=t;i++)
    {
        na[i] = a[i];
    }
    t++;
    na[t] = b;
    cout << "New Size is :: " << s << endl;
    a = na;
    cout << endl;
}
void push(int v)
{
    if(t<s)
    {
        t++;
        a[t] = v;
    }
    else
    {
        cout << "Can't Push, Must be Resize.." << endl << endl;
        rsize(v);
    }
}
void photocopy()
{
    cout << "Current Stack :: ";
    for(i=0;i<=t;i++)
    {
        cout << a[i] << " ";
    }
    cout << endl << endl;
}
int main()
{
    push(1);
    photocopy();
    push(2);
    photocopy();
    push(3);
    photocopy();
    push(4);
    photocopy();
    push(5);
    photocopy();

    return 0;
}

Comments