public class IntVector
extends java.lang.Object
Here is an example showing a vector being used:
... IntVector vec = new IntVector(); vec.addElement(int1); vec.addElement(int22); ... vec.insertElementAt(int3, 3); vec.removeElementAt(2); if (vec.size() > 5) ...
Modifier and Type | Field and Description |
---|---|
protected int |
count |
int[] |
items
This member is public for fast access.
|
Constructor and Description |
---|
IntVector()
Constructs an empty vector.
|
IntVector(int size)
Constructs an empty vector with a given initial size.
|
IntVector(int[] items)
Constructs a vector by directly assigning the given int array.
|
Modifier and Type | Method and Description |
---|---|
void |
addElement(int obj)
Adds an int to the end of the vector.
|
void |
addElements(int[] elements)
Appends an array of integers at the end of this vector.
|
boolean |
contains(int v)
Returns true if this vector contains the specified element.
|
void |
copyInto(int[] out)
Copies the items of this vector into the given array, which must have at least the current size of this vector.
|
void |
ensureBit(int index)
Useful method to use when this IntVector will act like a bit vector, through
the methods
isBitSet and setBit . |
int |
indexOf(int elem)
Finds the index of the given int.
|
int |
indexOf(int elem,
int index)
Finds the index of the given int.
|
void |
insertElementAt(int obj,
int index)
Inserts the object at the given index.
|
boolean |
isBitSet(int index)
Used to let this int vector act like a bit vector.
|
boolean |
isEmpty()
Returns if this IntVector is empty.
|
int |
peek()
Returns the last int, without removing it.
|
int |
pop()
Returns the last int, removing it.
|
void |
pop(int howMany)
Pops the given number of elements from this vector.
|
void |
push(int obj)
Pushes an int.
|
void |
qsort()
Does a quick sort in the elements of this IntVector
|
void |
removeAllElements()
Sets all elements in this vector to 0 and its size to 0.
|
void |
removeElement(int obj)
Deletes the given integer from this vector.
|
void |
removeElementAt(int index)
Deletes the int reference at the given index.
|
void |
reverse()
Reverses the order of the elements in this vector.
In a vector with n elements, the element of index 0 is moved to the index n-1, the element of index 1 is moved to the index n-2, and so on. |
void |
setBit(int index,
boolean on)
Used to let this int vector act like a bit vector.
|
void |
setSize(int newSize)
Sets the size of this vector.
|
int |
size()
Returns the number of ints in the vector.
|
int[] |
toIntArray()
Returns a new array with the added elements
|
public int[] items
protected int count
public IntVector()
public IntVector(int size)
public IntVector(int[] items)
public void ensureBit(int index)
isBitSet
and setBit
. Just call it
with the maximum bit index what will be used (starting from 0); then
you can safely use the two methods. This must be done because those methods
does not check the bounds of the array.public boolean isBitSet(int index)
public void setBit(int index, boolean on)
public void push(int obj)
public void pop(int howMany)
public int pop() throws ElementNotFoundException
ElementNotFoundException
- When the stack is empty.public int peek() throws ElementNotFoundException
ElementNotFoundException
- When the stack is empty.public boolean isEmpty()
public int size()
public int indexOf(int elem)
public int indexOf(int elem, int index)
public void removeElementAt(int index)
public void insertElementAt(int obj, int index)
public void addElement(int obj)
public void addElements(int[] elements)
elements
- array of integers to be added to this vector.public void removeElement(int obj)
public void removeAllElements()
public void qsort()
public int[] toIntArray()
public void setSize(int newSize) throws java.lang.ArrayIndexOutOfBoundsException
newSize
- the new size of this vectorjava.lang.ArrayIndexOutOfBoundsException
- if the new size is negativepublic void copyInto(int[] out)
public boolean contains(int v)
v
- element whose presence in this vector is to be testedpublic void reverse()