Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file...

80.2K

Verified Solution

Question

Programming

Complete the provided partial C++ Linked List program. Main.cppis given and Link list header file is also given. The giventestfile listmain.cpp is given for demonstration of unsorted listfunctionality. The functions header file is also given. Completethe functions of the header file linked_list.h below.

=========================================================

// listmain.cpp

#include \"Linked_List.h\"

int main(int argc, char **argv)
{
    float          f;
     Linked_List *theList;

     cout << \"Simple ListDemonstration\n\";
     cout << \"(List implemented as anArray - Do not try this at home)\n\n\";
     cout << \"Create a list and add a fewtasks to the list\";

     theList = new Linked_List(); //Instantiate a list object

     theList->Insert(5, 3.1f); // Note:The argument to the funtion should be a float
     theList->Insert(1, 5.6f); // A constantreal number like 3.1 is interpreted as
     theList->Insert(3, 8.3f); // a doubleunless it is explicitly defined as a float
     theList->Insert(2, 7.4f); // by addingan 'f' to the end of the number.
     theList->Insert(4, 2.5f);

     // Show what is in the list
     theList->PrintList();

     // Test the list length function
     cout << \"\nList now contains \"<< theList->ListLength() << \"items.\n\n\";

     // Test delete function
     cout << \"Testing delete of last itemin list.\n\";
     theList->Delete(4);
     theList->PrintList();

     // Test delete function
     cout << \"Testing delete of firstitem in list.\n\";
     theList->Delete(5);
     theList->PrintList();

     // Test delete function
     cout << \"Testing delete of a middleitem in list.\n\";
     theList->Delete(3);
     theList->PrintList();

     // Test delete function with a knownfailure argument
     cout << \"Testing failure in deletefunction.\n\";
     if(theList->Delete(4))
          cout<< \"Oops! Should not have been able to delete.\n\";
     else
          cout<< \"Unable to locate item to delete.\n\";

     // Test search (known failure)
     cout << \"Testing Search function.Search for key 3\n\";
     if(theList->Search(3, &f))
          cout<< \"Search result: theData = %f\n\", f;
     else
          cout<< \"Search result: Unable to locate item in list\n\";

     // Test search (known success)
     cout << \"Testing Search function.Search for key 2\n\";
     if(theList->Search(2, &f))
          cout<< \"Search result: theData = \" << f <<\"\n\";
     else
          cout<< \"Search result: Unable to locate item in list\n\";

     cout << \"\n\nEnd listdemonstration...\";

     return 0;
}

========================================================================================

// linked_list.h functions

#include
using namespace std;

// Define a structure to use as the list item
struct ListItem
{
     int     key;         
     float    theData;
      ListItem *next;
};

class Linked_List
{
     private:
          ListItem*head;              // Pointer to head of the list

     public:
         Linked_List();              // Class constructor
         ~Linked_List();             // Class destuctor
          voidClearList();            // Remove all items from the list
          boolInsert(int key, float f);// Add an item to the list
          boolDelete(int key);         //Delete an item from the list
          boolSearch(int key, float *retVal); // Search for an item in thelist
          intListLength();            // Return number of items in list
          boolisEmpty();              // Return true if list is empty
          boolisFull();               // Return true if list is full
          voidPrintList();            // Print all items in the list
};

#endif // End of list header

Answer & Explanation Solved by verified expert
4.2 Ratings (591 Votes)
linkedlisth functions include using namespace std Define a structure to use as the list item struct ListItem int key float theData ListItem next class LinkedList private Pointer to head of the list ListItem head public Class constructor LinkedList Class destuctor LinkedList    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students