IntegerList Class
Represents a list of integers.
public class IntegerList
- Inheritance:
- object object
Remarks
The implementation uses a short array to track the values until the values become too large, at which point an integer array is used. This saves on memory for smaller-valued lists.
Constructors
IntegerList(int)
Initializes a new instance of the IntegerList
class.
public IntegerList(int capacity)
Parameter | Type | Description |
---|---|---|
capacity | int | The initial capacity of the list. |
Properties
Count
Gets the number of integers in the list.
this[int]
Gets or sets the integer at the specified index.
[C#] In C#, this property is the indexer for the IntegerList
class.
public int this[int index] { get; set; }
Parameter | Type | Description |
---|---|---|
index | int | The index of the integer to return. |
Property Value
- int:
The integer at the specified index.
Methods
Add(int)
Adds an integer to the end of the list.
public int Add(int value)
Parameter | Type | Description |
---|---|---|
value | int | The value to add. |
Returns
- int:
The index at which the integer was added.
BinarySearch(int)
Performs a binary search for the specified value.
public int BinarySearch(int value)
Parameter | Type | Description |
---|---|---|
value | int | The value for which to search. |
Returns
- int:
The index of the specified value in the specified array, if value is found. If value is not found and value is less than one or more elements in array, a negative number which is the bitwise complement of the index of the first element that is larger than value. If value is not found and value is greater than any of the elements in array, a negative number which is the bitwise complement of (the index of the last element plus 1).
Remarks
This method should only be used if the integers in the list are guaranteed to be sorted.
Increment(int, int)
Increments all integers in the list after the specified index by the delta value.
public void Increment(int index, int delta)
Parameter | Type | Description |
---|---|---|
index | int | The index at which to start incrementing value. |
delta | int | The amount by which to increment. |
Remarks
This method should only be used if the integers in the list are guaranteed to be sorted.
Insert(int, int)
Inserts an integer into the list.
public void Insert(int index, int value)
Parameter | Type | Description |
---|---|---|
index | int | The index at which to insert. |
value | int | The value to insert. |
RemoveAt(int)
Removes the integer at the specified index from the list.
public void RemoveAt(int index)
Parameter | Type | Description |
---|---|---|
index | int | The index of the integer to remove. |
RemoveRange(int, int)
Removes a range of integers from the list.
public void RemoveRange(int index, int count)
Parameter | Type | Description |
---|---|---|
index | int | The zero-based starting index of the range of integers to remove. |
count | int | The number of integers to remove. |
ToArray()
Copies the integer of the collection to a new integer array.