-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicArrayVAC.java
More file actions
43 lines (36 loc) · 921 Bytes
/
DynamicArrayVAC.java
File metadata and controls
43 lines (36 loc) · 921 Bytes
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package datastructure;
import java.util.Arrays;
/**
*
* @author Vladimir Aca
* @param <T>
*/
public class DynamicArrayVAC<T> {
int size;
Object[] data;
public DynamicArrayVAC(){
this.size = 0;
this.data = new Object[1];
}
public int getSize(){
return this.data.length;
}
public void put(Object element){
ensureSize(this.size + 1);
this.data[this.size] = element;
this.size++;
}
public void ensureSize(int newCapacity){
if(newCapacity > this.getSize()){
this.data = Arrays.copyOf(data, this.getSize()*2);
}
}
public T getElement(int index){
return (T) this.data[index];
}
}