Question: DATA STRUCTURES Given the class specification of UnsortedType as below: struct NodeType //each node in the linked list { ItemType info; NodeType* next; }; class
DATA STRUCTURES
Given the class specification of UnsortedType as below:
struct NodeType
//each node in the linked list
{
ItemType info;
NodeType* next;
};
class UnsortedType //an pointer-based linked list
{
public:
UnsortedType();
// Constructor
void MakeEmpty();
// Function: Returns the list to the empty state.
bool IsFull() const;
// Function: Determines whether list is full.
int GetLength() const;
// Function: returns the number of elements in list.
void RetrieveItem(ItemType& item, bool& found);
// Function: Retrieves list element whose key matches item's key (if
// present).
void InsertItem(ItemType item);
// Function: Adds item to the end of list.
void DeleteItem(ItemType item);
// Function: Deletes the element whose key matches item's key.
void GetNextItem(ItemType& item);
// Function: Gets the next element in list.
private:
int length; // number of elements in the list
NodeType* listData; // pointer that points to the first node(head) of the list
NodeType* currentPos; // the position of current node under consideration
};
Assume the class ItemType is defined as
class ItemType
{
public:
ItemType();//constructor
int GetValue(); //return value
void Print();//display value
void Initialize(int number);//set value to number
private:
int value; //key of the item
};
a) (5pts) define(write the code for) function InsertItem(ItemType item)
b) (15 pts) Complete the client code below(i.e. fill the blanks with your code):
int main()
{
(1)___________________________//declare an object of UnsortedType and
//name it as myList
ItemType item1;
(2)___________________________//insert your code here to add item1
//to the myList
cout< (3)___________________________// display the length of myList (4)___________________________// check the myList is full or not (5)___________________________//delete the item1 in myList return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
