void testDelete (void){ printf("Testing delete!\n"); List l = setUpList(); assert(listLength(l) == START_LENGTH); //Delete the first element of the list deleteElement(l, 0); assert(getElement(l, 0) == 8); assert(listLength(l) == START_LENGTH - 1); //Delete an element from the middle of the list deleteElement(l, 1); assert(getElement(l, 1) == 4); assert(listLength(l) == START_LENGTH - 2); //Delete an element from the end of the list deleteElement(l, listLength(l) - 1); assert(getElement(l, 0) == 8); assert(listLength(l) == START_LENGTH - 3); disposeList(l); printf("Deleting tests passed!\n"); }
void testAdd (void){ printf("Testing add!\n"); List l = setUpList(); assert(listLength(l) == START_LENGTH); //Add one element to the beginning of the list addElement(l, 5, 0); assert(getElement(l,0) == 5); assert(listLength(l) == START_LENGTH + 1); //Add one element in the middle of the list addElement(l, 42, 3); // printList(l); assert(getElement(l,3) == 42); assert(listLength(l) == START_LENGTH + 2); //Add one element to the end of the list addElement(l, 99, listLength(l)); // printList(l); assert(getElement(l,listLength(l) - 1) == 99); assert(listLength(l) == START_LENGTH + 3); disposeList(l); printf("Adding tests passed!\n"); }
void disposeList(List *list){ Node *nextNode; if(list->head == NULL) return; nextNode = list->head; list->head = nextNode->next; free(nextNode); disposeList(list); }
Iterator keys(Hashmap *hash){ Iterator listIT,keysIT,arrayIT; Slot *slot; List *keys = (List*)hash->keys; disposeList(keys); keys = createList(); arrayIT = getIterator(&hash->bucket); while(arrayIT.hasNext(&arrayIT)){ slot = arrayIT.next(&arrayIT); listIT = getIteratorForList(slot->list); while(listIT.hasNext(&listIT)){ insertNode(keys,keys->length,listIT.next(&listIT)); } } keysIT = getIteratorForList(keys); return keysIT; }
_XList::~_XList() { if(anchor != NULL) disposeList(); itemcount = 0; }
_XMeshObjectManager::~_XMeshObjectManager() { disposeList(); }
void disposeSlot(Slot *slot){ disposeList(slot->list); free(slot); }