/* 	Adds an element to the end of the dynamic array

	param: 	v		pointer to the dynamic array
	param:	val		the value to add to the end of the dynamic array
	pre:	the dynArry is not null
	post:	size increases by 1
	post:	if reached capacity, capacity is doubled
	post:	val is in the last utilized position in the array
*/
void addDynArr(DynArr *v, TYPE val)
{
	if(v->size >= v->capacity) _dynArrSetCapacity(v,2*v->capacity);
	v->data[v->size] = val;
	v->size++;

}
Exemple #2
0
void addBackDynArr(DynArr *v, TYPE val)
{
	if (v->size >= v->capacity)
		_dynArrSetCapacity(v, 2*v->capacity);
	
	v->data[_absoluteIndex(v, v->size)] = val; //logical back...next open spot.. is at size
	v->size++;
}
/* 	Adds an element to the end of the dynamic array

	param: 	v		pointer to the dynamic array
	param:	val		the value to add to the end of the dynamic array
	pre:	the dynArry is not null
	post:	size increases by 1
	post:	if reached capacity, capacity is doubled
	post:	val is in the last utilized position in the array
*/
void addDynArr(struct DynArr *v, TYPE val)
{
    v->data[v->size] = val;
    v->size++;
    if (v->size == v->capacity) {
        v = _dynArrSetCapacity(v, v->capacity*2);
    }
}
/* 	Adds an element to the end of the dynamic array

	param: 	v		pointer to the dynamic array
	param:	val		the value to add to the end of the dynamic array
	pre:	the dynArry is not null
	post:	size increases by 1
	post:	if reached capacity, capacity is doubled
	post:	val is in the last utilized position in the array
*/
void addDynArr(DynArr *v, TYPE val)
{
    /* Check to see if a resize is necessary */
    if(v->size >= v->capacity){
        _dynArrSetCapacity(v, 2 * v->capacity);
    }
    v->data[v->size] = val;
    v->size++;
}
Exemple #5
0
/* ************************************************************************
 Deque Interface Functions
 *************************************************************************/
void addFrontDynArr(DynArr *v, TYPE val){
	if (v->size >= v->capacity) 
		_dynArrSetCapacity(v, 2*v->capacity);

	v->beg = v->beg - 1; //beginning is decremented!
	v->data[_absoluteIndex(v, 0)] = val;  //logical front is 0
	v->size++;
	
}
Exemple #6
0
/* 	Adds an element to the end of the dynamic array

	param: 	v		pointer to the dynamic array
	param:	val		the value to add to the end of the dynamic array
	pre:	the dynArry is not null
	post:	size increases by 1
	post:	if reached capacity, capacity is doubled
	post:	val is in the last utilized position in the array
*/
void addDynArr(DynArr *v, TYPE val)
{
	/* FIXME: You will write this function */
    assert(v != 0);
    if (v->size >= v->capacity) {
        _dynArrSetCapacity(v, 2 * v->capacity);
    }
    v->data[v->size] = val;
    v->size++;
}
/*	Put an item into the dynamic array at the specified location,
	overwriting the element that was there

	param: 	v		pointer to the dynamic array
	param:	pos		the index to put the value into
	param:	val		the value to insert 
	pre:	v is not null
	pre:	v is not empty
	pre:	pos >= 0 and pos < size of the array
	post:	index pos contains new value, val
*/
void putDynArr(DynArr *v, int pos, TYPE val)
{

	if (v->size >= v->capacity) _dynArrSetCapacity(v, 2 * v->capacity);

	for (int i = v->capacity - 1; i >= pos; i--)
		v->data[i] = v->data[i-1];
	v->data[pos] = val;
	v->size++;
}
Exemple #8
0
/* 	Push an element onto the top of the stack

	param:	v		pointer to the dynamic array
	param:	val		the value to push onto the stack
	pre:	v is not null
	post:	size increases by 1
			if reached capacity, capacity is doubled
			val is on the top of the stack
*/
void pushDynArr(DynArr *v, TYPE val)
{
	if (v->size == v->capacity)
	{
		_dynArrSetCapacity(v, 2 * v->capacity);
	}
	
	v->data[v->size] = val;

	v->size++;
}
/* 	Adds an element to the end of the dynamic array

	param: 	v		pointer to the dynamic array
	param:	val		the value to add to the end of the dynamic array
	pre:	the dynArry is not null
	post:	size increases by 1
	post:	if reached capacity, capacity is doubled
	post:	val is in the last utilized position in the array
*/
void addDynArr(DynArr *v, TYPE val)
{
	/* FIXME: You will write this function */
	assert(v != 0);
	// If size is equal or bigger than capacity, new capacity is set as double current capacity
	if (v->size >= v->capacity)
       		 _dynArrSetCapacity(v, 2 * v->capacity);

	v->data[v->size] = val;
	v->size++;

}
/* 	Adds an element to the end of the dynamic array

	param: 	v		pointer to the dynamic array
	param:	val		the value to add to the end of the dynamic array
	pre:	the dynArry is not null
	post:	size increases by 1
	post:	if reached capacity, capacity is doubled
	post:	val is in the last utilized position in the array
*/
void addDynArr(DynArr *v, TYPE val)
{
	assert(v != 0);

	if(v->size == v->capacity)
		_dynArrSetCapacity(v, (v->capacity * 2));

	v->data[v->size] = val;

	v->size++;

}
Exemple #11
0
/*  Adds an element to the end of the dynamic array

   param:  v		pointer to the dynamic array
   param:	val		the value to add to the end of the dynamic array
   pre:	the dynArry is not null
   post:	size increases by 1
   post:	if reached capacity, capacity is doubled
   post:	val is in the last utilized position in the array
 */
void addDynArr(DynArr *v, TYPE val)
{
								/* FIXME: You will write this function */
								/*Check if resize is needed*/
								if(v->size >= v->capacity) {
																_dynArrSetCapacity(v, 2 * v->capacity);
								}

								v->data[v->size] = val;
								v->size++;

}
Exemple #12
0
/* 	Adds an element to the end of the dynamic array

	param: 	v		pointer to the dynamic array
	param:	val		the value to add to the end of the dynamic array
	pre:	the dynArry is not null
	post:	size increases by 1
	post:	if reached capacity, capacity is doubled
	post:	val is in the last utilized position in the array
*/
void addDynArr(DynArr *v, TYPE val)
{
	/* FIXME: You will write this function */

	/* Check to see if a resize is necessary */
	if(v->size >= v->capacity)
		_dynArrSetCapacity(v, 2 * v->capacity);
	
	v->data[v->size] = val;
	v->size++;

}
Exemple #13
0
/*  Adds an element to the end of the dynamic array

    param:  v		pointer to the dynamic array
    param:	val		the value to add to the end of the dynamic array
    pre:	the dynArry is not null
    post:	size increases by 1
    post:	if reached capacity, capacity is doubled
    post:	val is in the last utilized position in the array
 */
void addDynArr(DynArr *v, void *val)
{

    assert(v != 0);

    /* Check to see if a resize is necessary */
    if( v->size >= v->capacity )
        _dynArrSetCapacity(v, 2 * v->capacity);

    v->data [ v->size ] = val;
    v->size++;

}
Exemple #14
0
/* 	Adds an element to the end of the dynamic array

	param: 	v		pointer to the dynamic array
	param:	val		the value to add to the end of the dynamic array
	pre:	the dynArry is not null
	post:	size increases by 1
	post:	if reached capacity, capacity is doubled
	post:	val is in the last utilized position in the array
*/
void addDynArr(DynArr *v, TYPE val)
{
	/* DONE: You will write this function */

	assert(v != 0);
	if (v->size >= v->capacity)
	{
		// If we need to grow, double the size
		_dynArrSetCapacity ( v, 2 * v->capacity);
	}
	v->data[v->size] = val;
	v->size++;
}
Exemple #15
0
/* 	Adds an element to the end of the dynamic array

	param: 	v		pointer to the dynamic array
	param:	val		the value to add to the end of the dynamic array
	pre:	the dynArry is not null
	post:	size increases by 1
	post:	if reached capacity, capacity is doubled
	post:	val is in the last utilized position in the array
*/
void addDynArr(DynArr *v, TYPE val)
{

	if (v->size == v->capacity)
	{
		_dynArrSetCapacity(v, 2 * v->capacity);
	}

	//printf("%d: \n", v->data[v->size]);		/*checking why val is coming in with a value of 0*/
	v->data[v->size] = val;

	v->size++;
	

}
/* 	Adds an element to the end of the dynamic array

	param: 	v		pointer to the dynamic array
	param:	val		the value to add to the end of the dynamic array
	pre:	the dynArr is not null
	post:	size increases by 1
	post:	if reached capacity, capacity is doubled
	post:	val is in the last utilized position in the array
*/
void addDynArr(DynArr *v, TYPE val)
{
	/* FIXME: You will write this function */
    if (v != 0) {
        int arrSize = sizeDynArr(v);
        int arrCap = v->capacity;

        if (arrCap == arrSize) { //if array is full
            _dynArrSetCapacity(v,(arrCap*2)); //create more space
        }

        v->data[arrSize] = val; //add value to end of the array
		v->size++;
    }
}
/* 	Push an element onto the top of the stack

	param:	v		pointer to the dynamic array
	param:	val		the value to push onto the stack
	pre:	v is not null
	post:	size increases by 1
			if reached capacity, capacity is doubled
			val is on the top of the stack
*/
void stack_push(struct DynArr *v, TYPE val)
{
    int x;

    for (x = v->size+1; x > 0; x--) {
        v->data[x] = v->data[x-1];
    }

    v->data[0] = val;

    v->size++;
    if (v->size == v->capacity) {
        v = _dynArrSetCapacity(v, v->capacity*2);
    }
}
Exemple #18
0
/* 	Adds an element to the end of the dynamic array

param: 	v		pointer to the dynamic array
param:	val		the value to add to the end of the dynamic array
pre:	the dynArry is not null
post:	size increases by 1
post:	if reached capacity, capacity is doubled
post:	val is in the last utilized position in the array
*/
void addDynArr(DynArr *v, TYPE val)
{
	assert(v != 0);

	int currentSize = sizeDynArr(v); //get size of the array

									 //resize the array if its full
	if (currentSize == v->capacity)
	{
		int newCapacity = v->capacity * 2;
		_dynArrSetCapacity(v, newCapacity);
	}

	v->data[currentSize] = val; //add element to the array
	v->size++; //update the number of elements in the array
}
Exemple #19
0
void addAtDynArr(DynArr *v, int idx, TYPE val)
{
  assert(v!= 0);
  assert(idx >=0 && idx <= v->size);

  int i;

  /* Check to see if a resize is necessary */
  if(v->size >= v->capacity)
    _dynArrSetCapacity(v, 2 * v->capacity);

  //Move elements down one
  for(i = v->size; i > idx; i--)
    v->data[i] = v->data[i-1];

  //putDynArr(v, idx, val); //this will increase size
  v->data[idx] = val;
  v->size++;

  assert(v->data[idx] == val);
}