Example #1
0
/** \brief  Add an element to arrayList and if is
 *          nessesary resize the array
 * \param pList ArrayList* Pointer to arrayList
 * \param pElement void* Pointer to element
 * \return int Return (-1) if Error [pList or pElement are NULL pointer] - (0) if Ok
 *
 */
int al_add(ArrayList* pList,void* pElement)
{
    int returnAux=-1;
    int value =0;
    void **plistAux;

    if (pList != NULL && pElement != NULL)
    {
        if (pList->size == pList->reservedSize)
        {
            value=resizeUp(pList);
        }


        plistAux=(pList->pElements) +(pList->size);// guardamos la ultima direccion de memoria libre de pElements

        if (value==0)
        {
            *plistAux=pElement;
            pList->size++;
            returnAux=0;
        }
    }

    return returnAux;
}
Example #2
0
/** \brief Inserts the element at the specified position
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \param pElement void* Pointer to element
 * \return int Return (-1) if Error [pList or pElement are NULL pointer or invalid index]
 *                  - ( 0) if Ok
 */
int al_push(ArrayList* pList, int index, void* pElement)
{
    int returnAux = -1;
    int i;
    int value=0;

    if (pList != NULL  && pElement != NULL && index<= al_len(pList) && index >=0)
    {
        if (al_len(pList) == pList->reservedSize)
        {
            value=resizeUp(pList);
        }
        if (value==0)
        {
            for (i = al_len(pList)-1; i >= index; i--)
                *((pList->pElements)+(i+1))=*((pList->pElements)+i);

            *((pList->pElements)+index)=pElement;
            pList->size++;
            returnAux=0;
        }

    }

    return returnAux;

}
Example #3
0
/** \brief Inserts the element at the specified position
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \param pElement void* Pointer to element
 * \return int Return (-1) if Error [pList or pElement are NULL pointer or invalid index]
 *                  - ( 0) if Ok
 */
int al_push(ArrayList* pList, int index, void* pElement)
{
    int i;
//    int j;
    int returnAux = -1;
    //void* auxList;
//    void* auxList2;
    //int cont=0;
    //int cont2=0;
    //int* size=pList->size;//
    if(pList!=NULL&& index<= pList->size && index>=0 && pElement!=NULL && resizeUp(pList)==0)
    {
        if(index == pList->size)
        {
            pList->add(pList, pElement);
        }
        else
        {

        for(i=pList->size;i>index;i--)
        {
            pList->pElements[i]=pList->pElements[i-1];
        }
        pList->pElements[index]=pElement;
        pList->size++;
        }
        returnAux=0;
    }
    return returnAux;
}
Example #4
0
void arrayListAdd(ArrayList a, elem e) {
	a->operation_count++;

	if(a->array_size == a->cluster_units * a->cluster_size) {
		resizeUp(a);
	}

	a->array[a->array_size++] = e;
}
Example #5
0
void append(List* p_List, void* element)
{
	if (p_List->size == p_List->reservedSize)
	{
		resizeUp(p_List);
	}
	p_List->pElements[p_List->size] = element;
	p_List->size++;
}
Example #6
0
void push(List* p_List,int index, void* element)
{// Desplaza los elementos e inserta en la posicion index
	if (p_List->size == p_List->reservedSize)
	{
		resizeUp(p_List);
	}
	expand(p_List, index);
	p_List->pElements[index] = element;
	p_List->size++;
}
Example #7
0
/** \brief  Add an element to arrayList and if is
 *          nessesary resize the array
 * \param pList ArrayList* Pointer to arrayList
 * \param pElement void* Pointer to element
 * \return int Return (-1) if Error [pList or pElement are NULL pointer] - (0) if Ok
 *
 */
int al_add(ArrayList* pList,void* pElement)
{
    int retorno=-1;
    if(pList!=NULL && pElement!=NULL)
    {
        resizeUp(pList);
        *((pList->pElements)+pList->size)=pElement;
        pList->size++;
        retorno=0;
    }
    return retorno;
}
Example #8
0
/** \brief  Add an element to arrayList and if is
 *          nessesary resize the array
 * \param pList ArrayList* Pointer to arrayList
 * \param pElement void* Pointer to element
 * \return int Return (-1) if Error [pList or pElement are NULL pointer] - (0) if Ok
 *
 */
int al_add(ArrayList* pList,void* pElement)
{
    int returnAux = -1;
    if(pList!=NULL && pElement!=NULL && resizeUp(pList)==0)
    {

        pList->pElements[pList->size]=pElement;
        pList->size++;//guarda cantidad de elemento y indice del primer lugar libre
        returnAux=0;
    }

    return returnAux;
}
Example #9
0
void push(ArrayList* self,int index,void* element){
	int i;
	
	for(i=self->size;i>=0;i--){
		if(i>=index){
			self->pElements[i]=self->pElements[i-1];
		}
		if(i==index){
			self->pElements[i]=element;
			resizeUp(self);
			break;
		}
	}
	
}
Example #10
0
/** \brief Inserts the element at the specified position
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \param pElement void* Pointer to element
 * \return int Return (-1) if Error [pList or pElement are NULL pointer or invalid index]
 *                  - ( 0) if Ok
 */
int al_push(ArrayList* pList, int index, void* pElement)
{
    int returnAux = -1;

    if(pList != NULL && pElement != NULL && index >= 0 && index <= pList->size)
    {
       if(resizeUp(pList) == 0)
       {
          expand(pList,index);
          pList->set(pList,index,pElement);
          returnAux = 0;
       }
    }

    return returnAux;
}
/** \brief  Add an element to arrayList and if is
 *          nessesary resize the array
 * \param pList ArrayList* Pointer to arrayList
 * \param pElement void* Pointer to element
 * \return int Return (-1) if Error [pList or pElement are NULL pointer] - (0) if Ok
 *
 */
int al_add(ArrayList* pList,void* pElement)
{
    int returnAux = -1;
    if(pList!=NULL&&pElement!=NULL)
    {
        returnAux=0;
        pList->pElements[pList->size]=pElement;
        pList->size++;
        if(pList->size==pList->reservedSize)
            if(resizeUp(pList)==-1)
                {
                    pList->size--;
                    return -1;
                }
    }
    return returnAux;
}
Example #12
0
/** \brief  Add an element to arrayList and if is
 *          nessesary resize the array
 * \param pList ArrayList* Pointer to arrayList
 * \param pElement void* Pointer to element
 * \return int Return (-1) if Error [pList or pElement are NULL pointer] - (0) if Ok
 *
 */
int al_add(ArrayList* pList,void* pElement)
{
    int returnAux = -1;

    if(pList != NULL && pElement != NULL)
    {
       if(resizeUp(pList) == 0)
       {

          pList->pElements[pList->size]=pElement;
          pList->size++;

       }
       returnAux = 0;
    }

    return returnAux;
}
/** \brief  Expand an array list
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \return int Return (-1) if Error [pList is NULL pointer or invalid index]
 *                  - ( 0) if Ok
 */
int expand(ArrayList* pList,int index)
{
    int returnAux = -1;
    if(pList!=NULL&&index>=0&&index<=pList->size)
    {
        returnAux=0;
        int i;
        for(i= pList->size ; i>index ; i--)//i>=???
            pList->pElements[i]=pList->pElements[i-1];

        pList->size++;
        if(pList->size==pList->reservedSize)//resize deberia ir antes
            if(resizeUp(pList)==-1)
                {
                    pList->size--;
                    return -1;
                }
    }
    return returnAux;
}
Example #14
0
/** \brief  Expand an array list
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \return int Return (-1) if Error [pList is NULL pointer or invalid index]
 *                  - ( 0) if Ok
 */
int expand(ArrayList* pList,int index)
{
    int returnAux = -1, expandir=0,i;

    if(pList->size == pList->reservedSize)
    {
        expandir = resizeUp(pList);
    }

    if(pList != NULL && index >= 0 && index <= pList->size && expandir != -1)
    {
        for(i=pList->size+1 ; i>=index; i--)
        {
            *((pList->pElements)+1+i) =  *((pList->pElements)+i);
        }
        returnAux = 0;
    }

    return returnAux;
}
Example #15
0
/** \brief  Add an element to arrayList and if is nessesary resize the array
 * \param pList ArrayList* Pointer to arrayList
 * \param pElement void* Pointer to element
 * \return int Return (-1) if Error [pList or pElement are NULL pointer] - (0) if Ok
 */
int al_add(ArrayList* pList,void* pElement)
{
    int returnAux = -1;
    int incremented = 0;

    if(pList != NULL && pElement != NULL)
    {
        if(pList->size == pList->reservedSize)
        {
            incremented=resizeUp(pList);
        }

        if(incremented!=-1)
        {
            *((pList->pElements) + pList->size) = pElement;
            // printf("%d",*(pList->pElements));
            pList->size += 1;
            returnAux=0;
        }
    }

    return returnAux;
}
Example #16
0
/** \brief Inserts the element at the specified position
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \param pElement void* Pointer to element
 * \return int Return (-1) if Error [pList or pElement are NULL pointer or invalid index]
 *                  - ( 0) if Ok
 */
int al_push(ArrayList* pList, int index, void* pElement)
{
    int returnAux = -1;
    // printf("Size es: %d",pList->size);
    if(pList != NULL && pElement != NULL && index >=0 && index <= pList->size )
    {
//            if(pList->size > 0&& !resizeUp(pList))
//            {
//                for (i=pList->size-1; i>index; i--)
//            {
//                pList->set(pList,i,pList->get(pList,(pList->pElements) + (i-1) )); /* *((pList->pElements) + i )=*((pList->pElements) + (i-1) );*/
//            }
//            }
        if(!resizeUp(pList))
        {
            expand(pList,index);
            pList->size++;
            al_set(pList,index,pElement);
            returnAux=0;
        }
    }
    return returnAux;
}
Example #17
0
/** \brief  Expand an array list
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \return int Return (-1) if Error [pList is NULL pointer or invalid index]
 *                  - ( 0) if Ok
 */
int expand(ArrayList* pList,int index)
{
    int returnAux = -1;
    int i;
    int value=0;

    if (pList != NULL && index < al_len(pList) && index >= 0)
    {
        if (al_len(pList) == pList->reservedSize)
            value=resizeUp(pList);

        if (value==0)
        {
            for (i = al_len(pList); i > index; i--)
                *((pList->pElements)+i)=*((pList->pElements)+i -1);

            pList->size++;
            returnAux=0;
        }

    }

    return returnAux;
}
Example #18
0
void add(ArrayList* pArray,int aux)
{
	pArray->elements[pArray->size-1] = aux;
	resizeUp(pArray);
}
Example #19
0
void add(ArrayList* pArray,void* aux){
	 pArray->pElements[pArray->size]=aux;
	  resizeUp(pArray);
}