Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++: Using an appropriate definition of ListNode, design a simple linked list class called StringList with the following member functions: void add (std::string); int positionOf

C++:

Using an appropriate definition of ListNode, design a simple linked list class called StringList with the following member functions:

void add (std::string);

int positionOf (std::string);

bool setNodeVal(int, std::string);

std::vector getAsVector();

a default constructor

a copy constructor

a destructor

The add() function adds a new node containing the value of the parameter to the end of the list. The positionOf() function returns the (zero-based) position in the list for the first occurrence of the parameter in the list, or -1 if that value is not in the list. In the setNodeVal() function, the first parameter represents a (zero-based) position in the list. The setNodeVal() function sets the value of the node at that position to the value of the string parameter. If the position parameter is >= the number of nodes in the list, the operation cannot be carried out and setNodeVal() should return false, otherwise it should be successful and return true. The getAsVector() function returns a vector with the same size, values and order as the StringList. The default constructor should initialize a new empty StringList object. The copy constructor should create a completely separate duplicate of a StringList object (a deep copy). The destructor should delete any memory that was dynamically allocated by the StringList object.

Files must be called: StringList.hpp and StringList.cpp

sample test case:

#include  #include  StringList myList; myList.add("haggis"); myList.add("stinky tofu"); myList.add("lutefisk"); std::vector vec = myList.getAsVector(); ASSERT_EQ(vec.at(0), "haggis"); ASSERT_EQ(vec.at(1), "stinky tofu"); ASSERT_EQ(vec.at(2), "lutefisk"); 

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

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

How many three-digit numbers are divisible by 7?

Answered: 1 week ago

Question

What is Indian Polity and Governance ?

Answered: 1 week ago