Question: could you implement this function please, im having issues with it. void makeList (const ListNode::value_type [],const size_t& count) class ListNode { public: typedef int value_type;

could you implement this function please, im having issues with it.

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

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;

};

This is the pseudocode, but i still have a hard time undertanding it.

Creating a List (makeList(const ListNode::value_type [],const size_t& count)) This function receives an array in the order that we want to add it to the linkedlist. Index 0 will be the head node, index n will be the last node.

First, create a node initialized with a data value and a NULL pointer. Set the "head" to point to the first node. Set up a current-pointer to the first node (or "head"). Get a data value for the next node. While more nodes to add { Create a new node initialized with the data value and a NULL pointer. Set the current-pointer link member ("next") to the new node. Set the current-pointer to point to the new node. Get a data value for the next node. }

Thanks.

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!