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 class OrderedList {

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 T *OrderedList::search(T target) { /* If target exists in list, return pointer to the target * otherwise, return null * */ }

/***************************************************/

template bool OrderedList::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 */ }

/***************************************************/

template bool OrderedList::remove(T target) { /* If target item exists in list, remove it, decrement length, and return true * otherwise, return false */ }

/***************************************************/

template void OrderedList::sort(int (*compare)(T, T)) { }

/***************************************************/

template void OrderedList::traverse(void (*visit)(int, T)) { }

/***************************************************/

template void OrderedList::traverseByCustomOrder(void (*visit)(int, T), int (*compare)(T, T)) { /* sort by custom order */ /* traverse the list */ /* sort by default order */ }

/***************************************************/

template double OrderedList::traverseDouble(double initialValue, double (*visit)(double, T)) { }

/***************************************************/

template int OrderedList::traverseInt(int initialValue, int (*visit)(int, T)) { }

/***************************************************/

template void OrderedList::traverseOut(ofstream *f, void (*visit)(ofstream *, T)) { } /* traverse for the purpose of outputing to the file */

/***************************************************/

template int OrderedList::getLength() { return length; }

/***************************************************/

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!