Initial commit
This commit is contained in:
138
application/source/engine/arrayUnsignedInteger.c
Normal file
138
application/source/engine/arrayUnsignedInteger.c
Normal file
@@ -0,0 +1,138 @@
|
||||
|
||||
|
||||
class arrayUnsignedInteger{
|
||||
|
||||
int capacity = 10;
|
||||
|
||||
int total = 0;
|
||||
|
||||
unsigned int * items = malloc( 10000000 );
|
||||
|
||||
int length()
|
||||
{
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
unsigned int get( int index )
|
||||
{
|
||||
|
||||
|
||||
return this->items[index];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void set( int index, unsigned int item )
|
||||
{
|
||||
|
||||
if ( index >= 0 && index < this->total ){
|
||||
|
||||
this->items[ index ] = item;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void resize( int capacity )
|
||||
{
|
||||
|
||||
int * items = realloc( this->items, sizeof( unsigned int ) * capacity );
|
||||
|
||||
|
||||
this->items = items;
|
||||
|
||||
this->capacity = capacity;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void add( unsigned int item )
|
||||
{
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
this->resize( this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
this->items[ this->total++ ] = item;
|
||||
|
||||
}
|
||||
|
||||
void delete( int index )
|
||||
{
|
||||
if ( index < 0 || index >= this->total ){
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
this->items[index] = 0.0;
|
||||
|
||||
for ( int i = index; i < this->total - 1; i++ ) {
|
||||
|
||||
this->items[i] = this->items[i + 1];
|
||||
|
||||
this->items[i + 1] = 0.0;
|
||||
|
||||
}
|
||||
|
||||
this->total--;
|
||||
|
||||
if ( this->total > 0 && this->total == this->capacity / 4 ){
|
||||
|
||||
this->resize( this->capacity / 2 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
unsigned int array_push( unsigned int item ) {
|
||||
|
||||
this->add( item );
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
void unshift( int item ) {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
this->total++;
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
this->resize( this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
for ( int i = length - 1; i >= 0; --i ) {
|
||||
|
||||
this->items[ i + 1 ] = this->items[ i ];
|
||||
|
||||
}
|
||||
|
||||
this->items[ 0 ] = item;
|
||||
|
||||
}
|
||||
|
||||
unsigned int pop() {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
int lastIndex = length - 1;
|
||||
|
||||
int lastItem = this->get( lastIndex );
|
||||
|
||||
this->delete( lastIndex );
|
||||
|
||||
return lastItem;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user