/** * Standard comparison function for the object list. Uses compare_items(). */ int object_list_standard_compare(const void *a, const void *b) { int result; const struct object *ao = cave->objects[(((object_list_entry_t *)a)->object)->oidx]; const struct object *bo = cave->objects[(((object_list_entry_t *)b)->object)->oidx]; /* If this happens, something might be wrong in the collect function. */ if (ao == NULL || bo == NULL) return 1; result = compare_items(ao, bo); /* If the objects are equivalent, sort nearest to farthest. */ if (result == 0) result = object_list_distance_compare(a, b); return result; }
int FileSystem::sort_table(ArrayList<FileItem*> *dir_list) { int changed; FileItem *temp; int i; changed = 1; while(changed) { changed = 0; for(i = 0; i < dir_list->total - 1; i++) { if(compare_items(dir_list, i, i + 1) > 0) // if(strcasecmp(dir_list->values[i]->name, dir_list->values[i + 1]->name) > 0) { temp = dir_list->values[i]; dir_list->values[i] = dir_list->values[i+1]; dir_list->values[i+1] = temp; changed = 1; } } } return 0; }