Isaac H.

asked • 05/09/23

I defined a class ListNode, with few extra definitions added: ListNode_str.h

Re-write this code as a template class, and re-name this file to ListNode.h

#pragma once
#include<iostream>
#include<string>
using std::string;

class ListNode
{
string value; // node's value
ListNode* prev; // link to the previous ListNode
ListNode* succ; // link to the successive ListNode

public:
ListNode(const string& v, ListNode* p = nullptr, ListNode* s = nullptr) :
value{ value }, prev{ p }, succ{ s }
{}

string get() const; // returns value
void set(string str); // sets value to v

ListNode* getPrev() const ; // returns the link to the previous ListNode
ListNode* getSucc() const; // returns the link to the successive ListNode

void setPrev(ListNode* node); // sets the link to the previous ListNode
void setSucc(ListNode* node); // sets the link to the successive ListNode

};


string ListNode::get() const // returns value
{
return value;
}


void ListNode::set(string v) // sets value to v
{
value = v;
}

ListNode* ListNode::getPrev() const
{ // returns the link to the previous ListNode
return prev;
}

ListNode* ListNode::getSucc() const
{ // returns the link to the successive ListNode
return succ;
}


void ListNode::setPrev(ListNode* node)
{ // sets the link to the previous ListNode
prev = node;
}

void ListNode::setSucc(ListNode* node)
{ // sets the link to the successive ListNode
succ = node;
}

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.