int main(int argc, char *argv[]) { Array_List *my_list = al_create_list(integer_compare_protocol, integer_deep_copy_protocol, integer_print_protocol); for (int i = 0; i < 50; i++) { My_Integer *p = malloc(sizeof(My_Integer)); p->x = i; al_add(my_list, p); } al_print_list(my_list); My_Integer *koo = malloc(sizeof(My_Integer)); koo->x = 20; if (al_contains(my_list, koo)) printf("Contains...\n"); al_clear_list(my_list); if (al_contains(my_list, koo)) printf("Contains...\n"); else printf("Doesn't contain...\n"); free(my_list); return 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 = -1; int contador = 0; int i; void* dato; if(pList != NULL && pList2 != NULL) { //int size = pList2->size; for(i=0; i<=pList2->size; i++) { dato = al_get(pList2,i); if(al_contains(pList,dato) == 1) { contador = contador +1; } } if(contador==pList2->size) { returnAux=1; } else { returnAux=0; } } return returnAux; }
void baja(ArrayList* lista) { char opcion; int i; int auxIden; int flag=0; int auxContains; ePelicula* auxPeli; showMessage("Ingrese identificador de la pelicula"); fflush(stdin); scanf("%d",&auxIden); for(i=0; i<lista->size; i++) { auxPeli=al_get(lista,i); auxContains=al_contains(lista,auxPeli); if(auxIden==auxPeli->identificador&&auxContains==1) { flag=1; system("cls"); showMessage("PELICULA ENCONTRADA"); system("pause"); printf("\nTitulo de la pelicula: %s\nAnio de la pelicula: %d\nNacionalidad de la pelicula: %s\nCodigo de Director de la pelicula: %d\n",auxPeli->titulo,auxPeli->anioPelicula,auxPeli->nacionalidad,auxPeli->director); showMessage("Desea eliminarla? s/n"); fflush(stdin); scanf("%c",&opcion); if(opcion=='s') { system("cls"); al_remove(lista,i); showMessage("PELICULA BORRADA"); system("pause"); system("cls"); } else { system("cls"); showMessage("PELICULA NO BORRADA"); system("pause"); system("cls"); } break; } } if(flag==0) { system("cls"); showMessage("PELICULA INEXISTENTE"); system("pause"); system("cls"); } }
/** \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 = -1; if(pList!=NULL&&pList2!=NULL) { int i; for(i=0;i<pList->size;i++) if(al_contains(pList,pList2->pElements[i])!=1) { returnAux=0; break; } if(i==pList->size) returnAux=1; } return returnAux; }
/* * mark basicBlock start and end, based on the given list of leaders. */ void markBasicBlockBoundary(InstrList *iList, ArrayList *leaders){ Instruction *instr; int i; for(i=0;i<iList->numInstrs;i++){ instr = getInstruction(iList, i); if(al_contains(leaders, (void *)(instr->addr))){ INSTR_SET_FLAG(instr, INSTR_IS_BBL_START); if(i>0){ instr = getInstruction(iList, i-1); INSTR_SET_FLAG(instr, INSTR_IS_BBL_END); } } } instr = getInstruction(iList, iList->numInstrs-1); INSTR_SET_FLAG(instr, INSTR_IS_BBL_END); //printInstruction(instr); }
/** \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 = -1; int i; // int cheAux=0; if(pList2!=NULL&&pList!=NULL&&pList->size!=0) { for (i=0;i<pList2->size;i++) { if(al_contains(pList,*((pList2->pElements)+i))==0) { returnAux=0; break; } else { returnAux=1; } } // for(i=0; i<pList2->size; i++) // { //// cheAux=-1; // for(j=0; j<pList->size; j++) // { // if(*((pList2->pElements)+i) ==*((pList->pElements)+j)) // { // cheAux++; // break; // } // } // } // if (cheAux!=pList->size) // { // returnAux=0; // } // if (cheAux==pList->size) // { // returnAux=1; // } } return returnAux; }