Created
October 24, 2017 03:09
-
-
Save mirsahib/2c96678f9fb6de7486cc03c9d7c8daf6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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