|
ContactCenters V. 0.9.9. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectumontreal.iro.lecuyer.contactcenters.ctmc.CircularIntArray
public class CircularIntArray
Represents a resizable circular array of integers. Any object of this class encapsulates an ordinary array of integers as well as an index of the starting position. Elements can be added to the array which grows as necessary. The first and last element of the array can be removed in constant time while removing any other element requires a linear time shift of the other elements in the array.
Constructor Summary | |
---|---|
CircularIntArray()
Constructs a new circular array of integers with a default initial capacity of 5 elements. |
|
CircularIntArray(int initialCapacity)
Constructs a new array of integers with the given initial capacity. |
Method Summary | |
---|---|
void |
add(int x)
Adds the element x at the end of this circular array. |
void |
clear()
Clears this circular array. |
CircularIntArray |
clone()
Returns a copy of this circular array of integers. |
int |
get(int i)
Returns the value of element i in this circular array. |
void |
init(CircularIntArray a)
Initializes this circular array of integers with the contents of another circular array a. |
static void |
main(String[] args)
|
int |
remove(int i)
Removes and returns the element with index i in the array. |
int |
removeFirst()
Removes and returns the first element of this circular array. |
int |
removeLast()
Removes and returns the last element of this circular array. |
void |
set(int i,
int e)
Sets the value of element i to e. |
int |
size()
Returns the size of this circular array. |
String |
toString()
Constructs and returns a string representation of the form [e1, e2, ...] of this array. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CircularIntArray()
public CircularIntArray(int initialCapacity)
initialCapacity
- the initial capacity of the
array.Method Detail |
---|
public void clear()
size()
is 0.
public void init(CircularIntArray a)
a
- the other circular array to copy.public void add(int x)
x
- the new element to add.public int removeFirst()
size()
method is 0, this method throws a
NoSuchElementException
.
public int removeLast()
size()
method is 0, this method throws a
NoSuchElementException
.
public int size()
public int get(int i)
i
- the index of the queried element.
public void set(int i, int e)
i
- the index of the element to modify.e
- the new value of the element.public int remove(int i)
removeFirst()
.
If the given index is size()
minus 1, this returns the
result of removeLast()
.
Otherwise, elements of the array are shifted appropriately to
remove the element.
i
- the index of the element to remove.
public CircularIntArray clone()
clone
in class Object
public String toString()
toString
in class Object
public static void main(String[] args)
|
ContactCenters V. 0.9.9. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |