Skip to content

Instantly share code, notes, and snippets.

@mirsahib
Created October 24, 2017 03:09
Show Gist options
  • Save mirsahib/2c96678f9fb6de7486cc03c9d7c8daf6 to your computer and use it in GitHub Desktop.
Save mirsahib/2c96678f9fb6de7486cc03c9d7c8daf6 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int row=10, num;
cin>>num;//if you take row as a input the program will have a bug
int *arrayList = new int[row];
int j=0;
while(num!=0){
if(j==row){
int *tempArray = new int[row*2];
for(int i=0;i<row;i++){
tempArray[i] = arrayList[i];
}
row = row*2;
arrayList = tempArray;
delete tempArray;
}
arrayList[j] = num;
cin>>num;
j++;
}
for(int i=0;i<j;i++){
cout<<*(arrayList+i)<<" ";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment