Question: C++ PROGRAMMING LANGUAGE template class OrderedList { private: /* number of items currently in the list */ int length; /* place where the list is
C++ PROGRAMMING LANGUAGE
template
private: /* number of items currently in the list */ int length;
/* place where the list is stored */ T nodes[_ARRAY_LIST_MAX_NUM_OF_NODES];
/* function that returns 1 if the left argument is greater * than the right argument, returns -1 if the right argument * is greater than the left argument, and 0 otherwise */ int (*defaultCompare)(T, T);
void sort(int (*compare)(T, T)); public: /* constructer */ OrderedList(int (*dc)(T, T)) { defaultCompare = dc; length = 0; }
/* destructer */ ~OrderedList() {}
int getLength();
bool remove(T target); /* If target item exists in list, remove it, decrement length, and return true * otherwise, return false */
bool insert(T newItem); /* If new item exists in list, or list is full, return false * otherwise, add item to list, increment length, and return true */
T *search(T target); /* If target exists in list, return pointer to the target * otherwise, return null * */
void traverse(void (*visit)(int, T)); /* For each node, run the visit function */
void traverseByCustomOrder(void (*visit)(int, T), int (*compare)(T, T)); /* sort nodes by compare * For each node, run the visit function * sort nodes by default comparison * */
double traverseDouble(double initialValue, double (*visit)(double, T)); /* for each node, run the visit function * The initial value is used as an arguement for the first * visit. The return value for each visit is used as an * arguement for the next visit. The return value for the * final visit is returned. * */
int traverseInt(int initialValue, int (*visit)(int, T)); /* for each node, run the visit function * The initial value is used as an arguement for the first * visit. The return value for each visit is used as an * arguement for the next visit. The return value for the * final visit is returned. * */
void traverseOut(ofstream *f, void (*visit)(ofstream *, T)); /* The file *f should already be open prior to calling traverseOut. * * For each node, run the visit function * */ };
/***************************************************/
template
/***************************************************/
template
/***************************************************/
template
/***************************************************/
template
/***************************************************/
template
/***************************************************/
template
/***************************************************/
template
/***************************************************/
template
/***************************************************/
template
/***************************************************/
template
/***************************************************/
#endif
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
