View Single Post
Old 01-23-2004, 01:51 PM   #9 (permalink)
Yakk
Wehret Den Anfängen!
 
Location: Ontario, Canada
Code:
void delete_ith(element_type* array, int* array_length, int i) {
  array[i] = array[*array_length-1];
  *array_length = *array_length-1;
}
Shortens the "length" of the array by one, deleting the ith element.

The actual memory allocated to the array might be the same, but 1 less element is used, and the ith element has been deleted/overwritten.

Quote:
b. Delete the ith element of a sorted array (the remaining array has to stay sorted, of course.)
In levels of increasing incorrectness:
1> it can't be done.
2> use markers for "unused value".
3> Implement a hash table instead of an array. Takes practical constant time, theoretical (when you pay attention to the dots on the i's) lg n time.
4> Implement a skip list instead of an array. Takes probabalistic-average lg n time.
__________________
Last edited by JHVH : 10-29-4004 BC at 09:00 PM. Reason: Time for a rest.
Yakk is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62