|
|
|
|
|
|
|
// Invariant (prior to test):
// list[length-1..count+1] have been shifted down
// && length - 1 >= count >= index - 1
strcpy(list[count+1], list[count]);
// Insert item
strcpy(list[index], item);
// Increment length of list
length++;
}
//******************************************************************
void SearchOrd(
/* inout */ String10 list[], // List to be searched
/* in */ const String10 item, // Item to be found
/* in */ int length, // Length of list
/* out */ int& index, // Item location if found
/* out */ Boolean& found ) // True if item is found
// Searches list for item, returning the index if item was found.
// If item was not found, SearchOrd returns the index where
// item belongs
// Precondition:
// length < MAX_LENGTH
// && list[0..length-1] are in ascending order
// && item is assigned
// Postcondition:
// list is the same as list@entry except that list[length] is
// overwritten to aid in the search
// && IF item is in list@entry
// found == TRUE && list[index] contains item
// ELSE
// found == FALSE && index is where item belongs
{
index = 0;
// Store item at position beyond end of list
strcpy(list[length],item); |
|
|
|
|
|