Need helpon following Question Write the definitions of the
Need helpon following Question. Write the definitions of the functions of the class orderedArrayListType that are not given in this chapter. Also, write a program to test various operations of this class.
Solution
A Function Declaration defines a named function variable without requiring variable assignment. Function Declarations occur as standalone constructs and cannot be nested within non-function blocks. It’s helpful to think of them as siblings of Variable Declarations. Just as Variable Declarations must start with “var”, Function Declarations must begin with “function”.
e.g.
1
2
3
function bar() {
return 3;
}
//////////////////orderedArrayListType/////////////
| 1 2 3 | function bar() { return 3; } //////////////////orderedArrayListType///////////// class orderedArrayListType { public: //Overload the assignment operator to perform deep copy const orderedArrayListType<T>& operator=(const orderedArrayListType<T> & old); //Function to determine whether the list is empty //Postcondition: Returns true if the list is empty; // otherwise, returns false. bool isEmpty() const; //Function to determine whether the list is full //Postcondition: Returns true if the list is full; // otherwise, returns false. bool isFull() const; //Function to determine the number of elements in the list //Postcondition: Returns the value of length. int listSize() const; //Function to determine the size of the list //Postcondition: Returns the value of maxSize. int maxListSize() const; //Function to output the elements of the list //Postcondition: Elements of the list are output on the // standard output device. void print() const; //Function to determine whether the item is the same //as the item in the list at the position specified by location //Postcondition: Returns true if the list[location] // is the same as the item; otherwise, // returns false. bool isItemAtEqual(int location, const T& item) const; //Function to remove the item from the list at the //position specified by location //Postcondition: The list element at list[location] is // removed and length is decremented by 1. // If location is out of range, an appropriate message // is displayed. void removeAt(int location); //Function to retrieve the element from the list at the //position specified by location //Postcondition: retItem = list[location] // If location is out of range, an appropriate // message is displayed. void retrieveAt(int location, T& retItem); //Function to remove all the elements from the list //After this operation, the size of the list is zero. //Postcondition: length = 0; void clearList(); // inserts in an ordered fashion void insertOrd(const T&); // searches for item in the ordered list // returns position if finds it, -1 if not int binarySearch(const T& item); //Postcondition: If the item is found, returns the location // in the array where the item is found; // otherwise, returns -1. int seqSearch(const T& item); //Function to remove an item from the list. The parameter //removeItem specifies the item to be removed. //Postcondition: If removeItem is found in the list, // it is removed from the list and length is // decremented by one. void remove(const T& removeItem); //constructor //Creates an array of the size specified by the //parameter size. The default array size is 100. //Postcondition: The list points to the array, length = 0, // and maxSize = size orderedArrayListType(int size = 100); //copy constructor - performs deep copy orderedArrayListType(const orderedArrayListType<T>& otherList); //destructor //Deallocates the memory occupied by the array. ~orderedArrayListType(); private: T *list; //array to hold the list elements int length; //variable to store the length of the list int maxSize; //variable to store the maximum size of the list //Private function to insert an item in the list at the //position specified by location. The item to be inserted //is passed as a parameter to the function. //Postcondition: Starting at location, the elements // of the list are shifted down, // list[location] = insertItem;, and // length++; // If the list is full or location is out of // range, an appropriate message is displayed. void insertAt(int location, const T& insertItem); }; |
