-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamicArray.cpp
More file actions
49 lines (43 loc) · 1.17 KB
/
dynamicArray.cpp
File metadata and controls
49 lines (43 loc) · 1.17 KB
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
40
41
42
43
44
45
46
47
48
49
#include <cstdlib>
#include <iostream>
using namespace std;
class dynamicArray{
public:
dynamicArray(int initSize=0):theSize(initSize),theCapacity(initSize + 1 ),s(0)
{
object = new int[theCapacity];
}
int size(){return theCapacity;}
void add(int x){
if(s==size()) resize();
object[s] = x ;
s++;
}
int resize(){
cout<<"............................"<<endl;
cout<<"yer degisimi yapiliyor"<<endl;
int s = theSize;
int *eski_sayilar = object ;
object = new int[theCapacity*2];
for(int k = 0 ; k<s ; k++){
object[k] = eski_sayilar[k];
}
theSize = s ;
theCapacity =theCapacity*2;
}
private:
int theSize;
int s;
int theCapacity;
int *object;
};
int main(int argc, char *argv[])
{
dynamicArray myD = dynamicArray(10);
for(int k =0 ; k<100 ; k++){
myD.add(4);
}
cout<<myD.size()<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}