|
|
|
|
|
|
|
{
String10 stuName; //An input student name
length = 0;
roster.get(stuName, 11); // Input at most 10 chars and
// leave room for '\0'
while (roster)
{
// Invariant (prior to test):
// student[0..length-1] contain the
// first "length" input names
roster.ignore(100, '\n'); // Consume chars through '\n'
Insert(student, length, stuName) ;
roster.get(stuName, 11);
}
}
//******************************************************************
void Insert(
/* inout */ String10 list[], // List to be changed
/* inout */ int& length, // Length of list
/* in */ const String10 item ) // Item to be inserted
// Inserts item into its proper place in the sorted list
// Precondition:
// length < MAX_LENGTH
// && list[0..length-1] are in ascending order
// && item is assigned
// Postcondition:
// item is in list
// && length == length@entry + 1
// && list[0..length-1] are in ascending order
// && IF item was already in list@entry
// item has been inserted before the one that was there
{
Boolean placeFound; // True if item is already in the list
int index; // Position where item belongs
int count; // Loop control variable
SearchOrd(list, item, length, index, placeFound);
// Shift list[index..length-1] down one
for (count = length - 1; count >= index; count--) |
|
|
|
|
|