< previous page page_704 next page >

Page 704
6. Rewrite function SearchOrd so that it searches a text file instead of an array.
7. Write a C++ function that searches a list list of length length for item. If item is found, it is deleted and the list is compacted (that is, all the components below item are moved up one place). Adjust length appropriately, item is of simple type ItemType.
8. Repeat Exercise 7, assuming that item is of string type StrType and list contains components of type StrType.
9. Write a C++ function that removes all occurrences of item in a list list of length length. Adjust length appropriately, item is of simple type ItemType.
10. Write a C++ function that takes two parallel arrays, isAbsent (Boolean) and score (float), and length as parameters. This function should store a zero into each position of score for which FALSE is in the parallel position of isAbsent. The other components of score should be left alone.
11. Write a C++ value-returning function that returns the sum of the products of parallel components in two int arrays, data and weight. Pass length as a parameter.
12. Modify function BinSearch so that index is where item should be inserted when found is FALSE.
13. Modify function Insert so that it uses function BinSearch rather than function SearchOrd to find the insertion point. (Assume that BinSearch has been modified as in Exercise 12.)
14. Given the declarations
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
const int MAX_LEN = 200;
typedef int ItemType;

ItemType list1[MAX_LEN];
ItemType list2[MAX_LEN];
int      length1;        // Length of list1
int      length2;        // Length of list2
ItemType item;
and viewing a list as an abstract data type, implement the following operations on a list.
a. A function named Empty that returns TRUE if a given list is empty. (Hint: Pass the length of the list to the function.)
b. A function named Full that returns TRUE if no more space is left in the array containing the list.
c. A function named Equal that takes two lists as parameters and returns TRUE if they are of the same length and each element in one list equals the corresponding element in the second list.
d. A function named Delete that takes a list and an item and searches the list for an instance of the item. If the item is found, it is removed fromthe list, and succeeding items are moved up to fulfill the empty space.
e. A function named DeleteAll that removes all instances of an item from a list without leaving gaps in the array.
f. A function named Component that returns a component of the list if a given position number (index value) is in the range 0 through length-1. The function should also return a Boolean flag named valid that is FALSE if the index is outside this range.

 
< previous page page_704 next page >