Esempio n. 1
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;

}
Esempio n. 2
0
/** \brief Returns true if pList list contains all of the elements of pList2
 * \param pList ArrayList* Pointer to arrayList
 * \param pList2 ArrayList* Pointer to arrayList
 * \return int Return (-1) if Error [pList or pList2 are NULL pointer]
 *                  - (0) if Not contains All - (1) if is contains All
 */
int al_containsAll(ArrayList* pList,ArrayList* pList2)
{
    int returnAux ;
    int i;
    int flag=0;

    if (pList == NULL || pList2 == NULL )
        returnAux=-1;
    else if (al_len(pList)!=al_len(pList2))
        returnAux=0;

    else
    {
        for (i=0; i<al_len(pList); i++)
        {
            if ( *((pList->pElements)+i ) == *((pList2->pElements)+i) )
                continue;
            else
            {
                returnAux=0;
                flag=1;//si esta bandera no cambia significa que nunca entro aca por lo tanto todos los valores comparados son iguales
                break;
            }
        }
        if (flag==0)
            returnAux=1;
    }

    return returnAux;
}
Esempio n. 3
0
/** \brief  Find if pList contains at least one element pElement
 * \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 but not found a element
 *                  - ( 1) if this list contains at least one element pElement
 *
 */
int al_contains(ArrayList* pList, void* pElement)
{
    int returnAux = -1;
    int i;
    //void** punt_list;
    int tamanio=al_len(pList);
    if(pList!=NULL && pElement!=NULL)
    {
        for(i=0;i<tamanio;i++)
        {
            if(pList->pElements[i]==pElement)
            {
                returnAux=1;
                break;
            }
            else
            {
                returnAux=0;
            }

        }

    }

    return returnAux;
}
Esempio n. 4
0
/** \brief  Checks to see if the item is passed as a parameter
 * \param pList ArrayList* Pointer to arrayList
 * \param pElement void* Pointer to elementFind if pList contains at least one element pElement
 * \return int Return (-1) if Error [pList or pElement are NULL pointer]
 *                  - ( 0) if Ok but not found a element
 *                  - ( 1) if this list contains at least one element pElement
 *
 */
int al_contains(ArrayList* pList, void* pElement)
{
    int returnAux = -1;
    int i;
    int flag=0;

    if (pList != NULL && pElement != NULL)
    {
        for (i=0; i<al_len(pList); i++)
        {
            if (*(pList->pElements+i) == pElement)
            {
                flag=1;
                break;
            }

        }
        if (flag)
        {
            returnAux=1;
        }
        else

            returnAux=0;
    }

    return returnAux;
}
Esempio n. 5
0
/** \brief  Contract 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 contract(ArrayList* pList,int index)
{
    int returnAux = -1;
    int i;

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

    return returnAux;
}
Esempio n. 6
0
/** \brief  Remove an element by index
 * \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 al_remove(ArrayList* pList,int index)
{
    int returnAux = -1;
    int i;

    if (pList !=NULL && index<al_len(pList) &&  index >=0)
    {
        for (i=index; i<al_len(pList); i++)
        {
            al_set(pList,index,al_get(pList,index+1));
        }
        pList->size--;

        returnAux = 0;
    }

    return returnAux;
}
Esempio n. 7
0
/** \brief  Get an element by index
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \return void* Return (NULL) if Error [pList is NULL pointer or invalid index] - (Pointer to element) if Ok
 *
 */
void* al_get(ArrayList* pList, int index)
{
    void* returnAux = NULL;

    if (pList !=NULL && index< al_len(pList) &&  index >=0 )
    {
        returnAux=*(pList->pElements+index);
    }
    return returnAux;

}
Esempio n. 8
0
/** \brief  Set a element in pList at index 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_set(ArrayList* pList, int index,void* pElement)
{
    int returnAux = -1;

    if (pList !=NULL && pElement!= NULL && index< al_len(pList) &&  index >=0)
    {
        *((pList->pElements)+index)=pElement;

        returnAux = 0;
    }

    return returnAux;
}
Esempio n. 9
0
/** \brief  Set a element in pList at index 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_set(ArrayList* pList, int index,void* pElement)
{
    int returnAux = -1;
    if(pList!=NULL && pElement!=NULL && (index>=0&&index<=al_len(pList)))
    {
        pList->pElements[index]=pElement;

        returnAux=0;
    }


    return returnAux;
}
Esempio n. 10
0
/** \brief Returns true if this list contains no elements.
 * \param pList ArrayList* Pointer to arrayList
 * \return int Return (-1) if Error [pList is NULL pointer] - (0) if Not Empty - (1) if is Empty
 */
int al_isEmpty(ArrayList* pList)
{
    int returnAux = -1;

    if (pList!= NULL)
    {
        if(al_len(pList)==0)
            returnAux=1;
        else
            returnAux=0;
    }

    return returnAux;
}
Esempio n. 11
0
/** \brief  Get an element by index
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \return void* Return (NULL) if Error [pList is NULL pointer or invalid index] - (Pointer to element) if Ok
 *
 */
void* al_get(ArrayList* pList , int index)
{
    void* returnAux = NULL;
    void** punt_index;
    if(pList!=NULL && (index>=0&&index<=al_len(pList)))
    {

        punt_index=pList->pElements[index];
        returnAux=punt_index;
    }


    return returnAux;
}
Esempio n. 12
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;
}
Esempio n. 13
0
/** \brief Removes all of the elements from this list
 * \param pList ArrayList* Pointer to arrayList
 * \return int Return (-1) if Error [pList is NULL pointer]
 *                  - ( 0) if Ok
 */
int al_clear(ArrayList* pList)
{
    int returnAux = -1;
    int i=0;
    if(pList!=NULL)
    {

        for(i=al_len(pList);i>0;i--)
        {
            pList->size--;
        }
        free(pList->pElements);
        returnAux=0;

    }
    return returnAux;
}
Esempio n. 14
0
/** \brief Sorts objects of list, use compare pFunc
 * \param pList ArrayList* Pointer to arrayList
 * \param pFunc (*pFunc) Pointer to fuction to compare elements of arrayList
 * \param order int  [1] indicate UP - [0] indicate DOWN
 * \return int Return (-1) if Error [pList or pFunc are NULL pointer]
 *                  - (0) if ok
 */
int al_sort(ArrayList* pList, int (*pFunc)(void*,void*), int order)
{
    int i,j;
    int retornFuncion;
    int retorno=-1;
    int tam =  al_len(pList);
    int flag=0;

    void* aux;


    if (pList != NULL && pFunc != NULL && (order==1 || order==0))
    {
        for (i=0; i< tam-1; i++ )
        {
            for(j=i+1; j< tam; j++ )
            {
                retornFuncion = pFunc(al_get(pList, i), al_get(pList, j));

                if(retornFuncion ==1 && order == 1)
                {
                    aux=al_get(pList,i);
                    al_set(pList,i,al_get(pList,j));
                    al_set(pList,j,aux);
                }
                else if(retornFuncion == -1 && order == 0)
                {
                    aux=al_get(pList,i);
                    al_set(pList,i,al_get(pList,j));
                    al_set(pList,j,aux);
                }
            }
        }

        flag=1;

    }

    if (flag)
    {
        retorno=0;
    }

    return retorno;

}
Esempio n. 15
0
/** \brief Returns the index of the first occurrence of the specified element
 * \param pList ArrayList* Pointer to arrayList
 * \param pElement void* Pointer to element
 * \return int Return (-1) if Error [pList or pElement are NULL pointer] - (index to element) if Ok
 */
int al_indexOf(ArrayList* pList, void* pElement)
{
    int returnAux = -1;
    int i;

    if(pList != NULL && pElement != NULL)
    {
       for(i = 0; i < al_len(pList); i++)
       {
           if(pList->pElements[i]==pElement)
           {
              returnAux = i;
           }
       }
    }

    return returnAux;
}
Esempio n. 16
0
/** \brief Returns an array containing all of the elements in this list in proper sequence
 * \param pList ArrayList* Pointer to arrayList
 * \return ArrayList* Return  (NULL) if Error [pList is NULL pointer]
 *                          - (New array) if Ok
 */
ArrayList* al_clone(ArrayList* pList)
{
    ArrayList* returnAux = NULL;
    ArrayList* pList2=al_newArrayList();
    int i;

    if (pList != NULL)
    {
        for (i=0; i<al_len(pList) ; i++)
        {
            al_add(pList2,pList->pElements+i);
            //al_add(pList2,al_get(pList(pList->pElements)+i));
        }
        returnAux=pList2;
    }

    return returnAux;
}
Esempio n. 17
0
/** \brief Returns a new arrayList with a portion of pList between the specified
 *         fromIndex, inclusive, and toIndex, exclusive.
 * \param pList ArrayList* Pointer to arrayList
 * \param from int Initial index of the element (inclusive)
 * \param to int Final index of the element (exclusive)
 * \return int Return (NULL) if Error [pList is NULL pointer or invalid 'from' or invalid 'to']
 *                  - ( pointer to new array) if Ok
 */
ArrayList* al_subList(ArrayList* pList,int from,int to)
{
    void* returnAux = NULL;
    ArrayList* subList;
    int i;

    if (pList !=NULL && from>=0 && to<=al_len(pList) && to>from )
    {
        subList=al_newArrayList();
        for (i=0;  i<to - from;  i++)
        {
            pList->add( subList, pList->get(pList, from+i) );
        }
        returnAux=subList;
    }

    return returnAux ;
}
Esempio n. 18
0
/** \brief Remove the item at the given position in the list, and return it.
 * \param pList ArrayList* Pointer to arrayList
 * \param index int Index of the element
 * \return int Return (NULL) if Error [pList is NULL pointer or invalid index]
 *                  - ( element pointer) if Ok
 */
void* al_pop(ArrayList* pList,int index)
{
    void* returnAux=NULL;
    int i;

    if ( pList != NULL && index<al_len(pList) && index >= 0  )
    {
        returnAux=al_get(pList,index);

        for (i=index; i<pList->size; i++)
        {
            al_set(pList,index,al_get(pList,index+1));
        }
        pList->size--;

    }

    return returnAux;
}
Esempio n. 19
0
void informar(ArrayList* lista,ArrayList* listaDirec)
{
    int opcion;
    printf("1-Top 3 Mejores Peliculas\n");
    printf("2-Top 5 Peores Peliculas\n");
    scanf("%d",&opcion);
    switch(opcion)
    {
        case 1:
            if(lista->size>3)
            {
                int i,j;
                int largo;
                ArrayList* listaOrdenada;
                ArrayList* top3;
                listaOrdenada=al_clone(lista);
                al_sort(listaOrdenada,compareFilms,0);
                ePelicula* pAuxP;
                eDirector* pAuxD;
                top3=al_subList(listaOrdenada,0,2);
                largo=al_len(top3);
                for(i=0; i<largo; i++)
                {
                    pAuxP=al_get(top3,i);
                    for(j=0; j<listaDirec->size; j++)
                    {
                        pAuxD=al_get(listaDirec,j);
                        if(pAuxP->director==pAuxD->codDirec)
                        {
                            break;
                        }
                    }
                    printf("----------[%d]----------",(i+1));
                    printf("\nTitulo de la pelicula: %s\nDirector de la pelicula: %s\nNacionalidad de la pelicula: %s\nPuntaje: %d/100\n",pAuxP->titulo,pAuxD->nombre,pAuxP->nacionalidad,pAuxP->puntaje);
                }
                al_deleteArrayList(listaOrdenada);
                al_deleteArrayList(top3);
            }
            else
            {
                showMessage("IMPOSIBLE REALIZAR TOP SIN LA CANTIDAD CORRECTA DE PELICULAS");
            }
            break;
        case 2:
            if(lista->size>5)
            {
                int i,j;
                int largo;
                ArrayList* listaOrdenada;
                ArrayList* top5;
                listaOrdenada=al_clone(lista);
                al_sort(listaOrdenada,compareFilms,1);
                ePelicula* pAuxP;
                eDirector* pAuxD;
                top5=al_subList(listaOrdenada,0,4);
                largo=al_len(top5);
                for(i=0;i<largo;i++)
                {
                    pAuxP=al_get(top5,i);
                    for(j=0;j<listaDirec->size;j++)
                    {
                        pAuxD=al_get(listaDirec,j);
                        if(pAuxP->director==pAuxD->codDirec)
                        {
                            break;
                        }
                    }
                    printf("----------[%d]----------",(i+1));
                    printf("\nTitulo de la pelicula: %s\nDirector de la pelicula: %s\nNacionalidad de la pelicula: %s\nPuntaje: %d/100\n",pAuxP->titulo,pAuxD->nombre,pAuxP->nacionalidad,pAuxP->puntaje);
                }
                al_deleteArrayList(listaOrdenada);
                al_deleteArrayList(top5);
            }
            else
            {
                showMessage("IMPOSIBLE REALIZAR TOP SIN LA CANTIDAD CORRECTA DE PELICULAS");
            }
            break;
    }


}