DozorovaA.A_FourthLabWork #4

Closed
DozorovaA.A wants to merge 7 commits from FourthLabWork into ThirdLabWork
2 changed files with 10 additions and 10 deletions
Showing only changes of commit b7dba8c76a - Show all commits

Binary file not shown.

View File

@ -2,15 +2,15 @@ import java.lang.reflect.Array;
import java.util.ArrayList;
public class SetArmoredCarsGeneric<T> {
private T[] _places;
private ArrayList<T> _places;
public SetArmoredCarsGeneric(int count)
{
_places = (T[]) new Object[count];
_places = new ArrayList<T>(count);
}
public int getCount() {
return _places != null ? _places.length : 0;
return _places != null ? _places.size() : 0;
}
public int Insert(T armoredCar)
@ -23,13 +23,13 @@ public class SetArmoredCarsGeneric<T> {
if (position < 0 || position >= getCount())
return -1;
if (!(_places[position] == null))
if (!(_places.get(position) == null))
{
Review

Закомментированного кода быть не должно

Закомментированного кода быть не должно
int index_empty = -1;
// поиск первого пустого элемента
for (int i = position + 1; i < getCount(); i++)
{
if (_places[i] == null)
if (_places.get(i) == null)
{
index_empty = i;
}
@ -40,11 +40,11 @@ public class SetArmoredCarsGeneric<T> {
{
for (int i = index_empty; i > position; i--)
{
_places[i] = _places[i - 1];
_places.set(i, _places.get(i-1));
}
}
}
_places[position] = armoredCar;
_places.set(position, armoredCar);
return position;
}
@ -52,8 +52,8 @@ public class SetArmoredCarsGeneric<T> {
{
if (position < 0 || position >= getCount())
return null;
T armoredCar = _places[position];
_places[position] = null;
T armoredCar = _places.get(position);
_places.set(position, null);
return armoredCar;
}
@ -61,6 +61,6 @@ public class SetArmoredCarsGeneric<T> {
{
if (position < 0 || position >= getCount())
return null;
return _places[position];
return _places.get(position);
}
}