Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions

Question

What are negative messages? (Objective 1)

Answered: 1 week ago