-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
39 lines (32 loc) · 890 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
using namespace std;
int main()
{
int capacity = 5;
int* number = new int[capacity];
int entries = 0;
while(true) {
cout << "Numbers: ";
cin >> number[entries];
if(cin.fail()) break;
entries++;
if(entries == capacity) {
// crear una variable temporal para incremenentar la memoria asignada
capacity *= 2;
int* temp = new int[capacity];
// copiar los elementos de temp al arreglo de number
for(int i= 0; i < entries; i++) {
temp[i] = number[i];
}
delete[] number;
number = temp;
}
if( entries > capacity) {
cout << "Warning: Exceeded capacity!" << endl;
};
}
for(int i = 0; i < entries; i++) {
cout << number[i] << ",";
}
return 0;
}