Question: Implement a LinkedList class that creates and manipulates a linked list of Items, defined as class Item { private: const char *l; int key; public:

Implement a LinkedList class that creates and manipulates a linked list of Items, defined as

class Item { private: const char *l; int key; public: Item(int k, const char*s){ key = k; l = s; } int getKey(){ return key; }; const char * getl(){ return l; }; Item(const Item &other){ key = other.key; l = other.l; };

. Implement the class in a file named LinkedList.cpp. Also copy the code into this file, as insurance.

Your LinkedList class must include the following:

  • [3 pts] Public default constructor that creates an empty list.

  • [3 pts] Public copy constructor that creates a copy of the list. (NOTE: The copy must include new list nodes -- it can't just point to the same nodes in this list.)

  • [4 pts] Public destructor that deletes all the nodes of the list.

  • [4 pts each] Public methods:

    • int length() -- returns the number items in the list (int)

    • void append(const Item&) -- adds a copy of the Item to the end of the list (no return value)

    • bool remove(Item&) -- removes the first item of the list and stores it into the reference passed in; returns true if item is removed, false if list was empty

    • bool empty() -- returns true if list is empty, false if not

    • bool insert(const Item&, int) -- adds a copy of the Item to the list at the specified position; returns true if successfully added, false if list was too small (e.g., insert at position 5, but the list only has 2 items)

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!