-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayList.java
66 lines (56 loc) · 1.25 KB
/
ArrayList.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
public class ArrayList<E>{
private E[] array;
private int size;
private int capacity;
//CONSTRUCTOR//
public ArrayList(){
capacity = 100;
size = 0;
array = (E[])new Object[capacity];
}
//Adder (Calls resize() method)
public void add(E e){
array[size] = e;
size++;
if(size == capacity-1){
resize();
}
}
//return maximum element of the array
//method yanlis calisiyor.
public int IntegerMax(){
int max = (int)array[0];
for(int i = 0; i < size; i++){
if((int)array[i]> max){
max = (int)array[i];
}
}
return max;
}
public void resize(){
E[] temp = (E[])new Object[capacity*2];
for(int i=0 ; i < array.length ; i++){
temp[i] = array[i];
}
array = temp;
capacity = capacity*2;
}
//Getter
public E get(int i){
return array[i];
}
public int size(){
return size;
}
//-
public void setSize(int new_size){
size = new_size;
}
//Setter
public void set(int i , E e){
array[i] = e;
}
/*
This class is a basic implementation of ArrayList<>
*/
}