-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayList.java
More file actions
69 lines (67 loc) · 1.03 KB
/
Copy pathArrayList.java
File metadata and controls
69 lines (67 loc) · 1.03 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class ArrayList<D> implements List<D>
{
Object array[];
Integer size;
Integer buffer;
ArrayList()
{
buffer=5;
size=0;
array=new Object[buffer];
}
public boolean isempty()
{
return (size==0);
}
public void add(D i)
{
if(size==buffer)
{
Object arr[]=new Object[buffer*2];
buffer*=2;
for(Integer j=0;j<size;j++)
{
arr[j]=array[j];
}
array=arr;
array[size]=i;
size++;
}
else
{
array[size]=i;
size++;
}
}
public void Traverse()
{
Integer a=0;
while(a<size)
{
System.out.println(array[a]);
a+=1;
}
}
public Integer Search(D o)
{
Integer i;
for(i=0;i<size;i++)
{
if(array[i]==o)
break;
}
return i;
}
public D getElementAt(Integer pos)
{
try{
if(pos<0||pos>=size)
throw new BoundException();
}
catch(BoundException e)
{e.printError(pos);
return null;
}
return (D)array[pos-1];
}
}