Could you please implement this Thanks ifndef LINKEDLISTH de

Could you please implement this. Thanks

#ifndef LINKEDLIST_H

#define LINKEDLIST_H

#include <cstdlib>

#include<iostream>

class ListNode

{

public:

typedef int value_type;

ListNode (value_type d = value_type(), ListNode* n = NULL) { datum = d; next = n; }

  

//Assessor

value_type getDatum () const { return datum; }

ListNode const* getNext () const { return next; }

  

//Mutator

void setDatum (const value_type& d) {datum = d; }

ListNode* getNext () { return next; }

void setNext (ListNode* new_link) {next = new_link; }

  

private:

value_type datum;

ListNode* next;

};

  

  

class LinkedList

{

public:

LinkedList ();

virtual ~LinkedList ();

  

void insertItem (ListNode::value_type);

void makeList (const ListNode::value_type [],const size_t& count);

void deleteList ();

  

//The following friend function is implemented in lablinklist.cpp

friend std::ostream& operator<<(std::ostream&, const LinkedList&);

private:

ListNode* head;

};

#endif

///Main

#include <iostream>

#include \"ll.h\"

using namespace std;

int main() {

  

LinkedList list1;

  

//Test of adding items out of order

list1.insertItem(5);

list1.insertItem(20);

list1.insertItem(10);

cout << list1 << endl;

  

//Test of deleting entire list

list1.deleteList();

cout << list1 << endl;

  

//Add items again in same order as before

list1.insertItem(5);

list1.insertItem(20);

list1.insertItem(10);

cout << list1 << endl;

  

//Now replace list with a new one in a specific order

int pow2[] = {1,2,4,8,16,32,16,8,4,2,1};

list1.makeList(pow2,sizeof(pow2)/sizeof(int));

cout << list1 << endl;

  

//Returning a non-zero number, if not 3, then we know it seg-faulted

return 3;

}

  

std::ostream& operator<<(std::ostream& os, const LinkedList &srcList) {

  

//Set a current-pointer to the \"head\".

ListNode* cursor = srcList.head;

  

//While current-pointer is not NULL

while ( cursor != NULL )

{

//Print the data member (\"datum\") of the current node

os << \"->[\" << cursor->getDatum() << \"]\";

//Set the current-pointer to the \"next\" node in the list.

cursor = cursor->getNext();

}

//Print out a basic termination symbol

std::cout << \"--X\" << std::endl;

  

return os;

}

Solution

ll.h remains same as provided

//ll.cpp

#include \"ll.h\"

LinkedList::LinkedList()
{
   head = NULL;
}
LinkedList::~LinkedList()
{
   ListNode *tmp = head;
   while (tmp != NULL)
   {
       head = head->getNext();
       delete tmp;
       tmp = head;
   }
}

void LinkedList::insertItem(ListNode::value_type item)
{
   ListNode *newNode,*cur = head;
   newNode = new ListNode;
   newNode->setDatum(item);
   newNode->setNext(NULL);
   if (head == NULL)
   {
       head = newNode;
   }
   else
   {

       while (cur->getNext() != NULL)
       {
           cur = cur->getNext();
       }
       cur->setNext(newNode);
   }

}

void LinkedList::makeList(const ListNode::value_type num[], const size_t& count)
{
   int i = 0;
   while ( i < count)
   {
       insertItem(num[i++]);
   }
}

void LinkedList::deleteList()
{
   ListNode *tmp = head;
   while (tmp != NULL)
   {
       head = head->getNext();
       delete tmp;
       tmp = head;
   }
}

std::ostream& operator<<(std::ostream& os, const LinkedList &srcList) {

   //Set a current-pointer to the \"head\".
   ListNode* cursor = srcList.head;

   //While current-pointer is not NULL
   while (cursor != NULL)
   {
       //Print the data member (\"datum\") of the current node
       os << \"->[\" << cursor->getDatum() << \"]\";
       //Set the current-pointer to the \"next\" node in the list.
       cursor = cursor->getNext();
   }
   //Print out a basic termination symbol
   std::cout << \"--X\" << std::endl;

   return os;

}

---------------------------------------------------------------------------------------------------------------

//main.cpp

remians same as provided

------------------------------------------------------------------------------------------

//output

->[5]->[20]->[10]--X

--X

->[5]->[20]->[10]--X

->[5]->[20]->[10]->[1]->[2]->[4]->[8]->[16]->[32]->[16]->[8]->[4]->[2]->[1]--X

Could you please implement this. Thanks #ifndef LINKEDLIST_H #define LINKEDLIST_H #include <cstdlib> #include<iostream> class ListNode { public: typ
Could you please implement this. Thanks #ifndef LINKEDLIST_H #define LINKEDLIST_H #include <cstdlib> #include<iostream> class ListNode { public: typ
Could you please implement this. Thanks #ifndef LINKEDLIST_H #define LINKEDLIST_H #include <cstdlib> #include<iostream> class ListNode { public: typ
Could you please implement this. Thanks #ifndef LINKEDLIST_H #define LINKEDLIST_H #include <cstdlib> #include<iostream> class ListNode { public: typ
Could you please implement this. Thanks #ifndef LINKEDLIST_H #define LINKEDLIST_H #include <cstdlib> #include<iostream> class ListNode { public: typ

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site