Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement the following specification of UnsortedType using a circular linked li

ID: 3638245 • Letter: I

Question

Implement the following specification of UnsortedType using a circular linked list as the implementation structure.

template<class ItemType>
structNodeType;

/* Assumption: ItemType is a type for which the operators
"<" and "==" are defined—either an appropriate built-in type or a class that overloads these operators. */
template<class ItemType>
classUnsortedType
{
public:
// Class constructor, destructor, and copy constructor
UnsortedType();
~UnsortedType();
UnsortedType(constUnsortedType<ItemType>&);

void operator=(UnsortedType<ItemType>);

boolIsFull() const;
// Determines whether list is full.
// Post: Function value = (list is full)

intGetLength() const;
// Determines the number of elements in list.
// Post: Function value = number of elements in list.

voidRetrieveItem(ItemType& item, bool& found);
// Retrieves list element whose key matches item's key
// (if present).
// Pre: Key member of item is initialized.
// Post: If there is an element someItem whose key matches
// item's key, then found = true and item is a copy of
// someItem; otherwise found = false and item is
// unchanged.
// List is unchanged.


voidInsertItem(ItemType item);
// Adds item to list.
// Pre: List is not full.
// item is not in list.
// Post: item is in list.

voidDeleteItem(ItemType item);
// Deletes the element whose key matches item's key.
// Pre: Key member of item is initialized.
// One and only one element in list has a key matching
// item's key.
// Post: No element in list has a key matching item's key.

voidResetList();
// Initializes current position for an iteration through the
// list.
// Post: Current position is prior to list.

voidGetNextItem(ItemType&);
// Gets the next element in list.
// Pre: Current position is defined.
// Element at current position is not last in list.
// Post: Current position is updated to next position.
// item is a copy of element at current position.

private:
NodeType<ItemType>* listData;
int length;
NodeType<ItemType>* currentPos;
};

Deliverables
• A listing of the specification and implementation files for UnsortedType
• A listing of the driver program for your test plan
• A listing of the test plan as input to the driver.
• A listing of the output from the driver.

Explanation / Answer

#include #include #include #include using namespace std; class linklist { private: struct node { int a; node *link; }*p; public: linklist(); void append( int num ); void add_as_first( int num ); void addafter( int c, int num ); void del( int num ); void display(); }; linklist::linklist() { p=NULL; } void linklist::append(int num) { node *q,*t,*o; if(p==NULL) { p=new node; p->a=num; p->link=NULL; } else { q=p; while(q->link!=NULL) { q=q->link; } o=new node; o->a=num; o->link=NULL; q->link=o; } } void linklist::add_as_first(int num) { node *q; q = new node; q->a = num; q->link = p; p = q; } void linklist::addafter( int c, int num) { node *q,*t,*o; q=p; int i; for(i=0;ilink; if(q== NULL) { coutlink; delete q; return; } r = q; while( q!=NULL ) { if( q->a == num ) { r->link = q->link; delete q; return; } r = q; q = q->link; } cout