Please send questions to
st10@humboldt.edu .
#ifndef string_list2_H
#define string_list2_H
/*-----------------------------------------------------------
a string_list2 is a class:
string_list2
...representing a list with:
a size,
the strings it currently contains
template for a function involving a string_list2:
ret_type process_string_list2(string_list2 a_string_list2)
{
return ...a_string_list2.get_length()...
...a_string_list2.get_element(i)...
}
-------------------------------------------------------------*/
#include <string>
#include "string_node.h"
using namespace std;
class string_list2
{
public:
// constructor
string_list2();
// destructor
~string_list2();
// copy constructor
string_list2(const string_list2& a_string_list2);
// selectors
int get_length() const;
// signature: string_list::get_element: int -> string
// purpose: expects the "index" (starting with 0, like an
// array) of the list element desired, and produces
// the string at that position in this string_list
// examples: for:
// string_list greetings;
// greetings.add("hi");
// greetings.add("hello");
// greetings.add("howdy");
//
// greetings.get_element(0) == "hi"
// greetings.get_element(2) == "howdy"
string get_element(int index) const;
// modifiers
// signature: string_list::add: string -> void
// purpose: expects a string, and produces nothing, but
// has the side-effect of adding the given string
// to the end of the list (making it its last element)
// examples: after:
// string_list greetings;
// greetings.add("hi");
//
// now:
// greetings.get_size() == 1
// greetings.get_element(0) == "hi"
//
// and then after:
// greetings.add("hello");
//
// now:
// greetings.get_size() == 2
// greetings.get_element(1) == "hello"
void add(string new_string);
// signature: string_list::remove: string -> bool
// purpose: expects a string, and tries to remove its
// first instance from the calling string_list,
// producing true if it finds it and removes it,
// and producing false if the string is not in the
// string_list
// examples: after:
// string_list greetings;
// greetings.add("hi");
// greetings.add("howdy");
// greetings.add("hi");
// greetings.add("hello");
//
// greetings.remove("hi") == true
// and after:
// greetings.get_size() == 3
// greetings.get_element(0) == "howdy"
// (and greetings contains "howdy", "hi", "hello")
//
// greetings.remove("bonjour") == false
// greetings.get_size() == 3
// greetings.get_element(0) == "howdy"
// (and greetings contains "howdy", "hi", "hello")
bool remove(string a_string);
// overloaded operator =
string_list2& operator =(const string_list2& right_side);
private:
// data fields
string_node* first; // pointer to the first string_list element
int curr_size; // number of strings actually in the linked
// list, currently
};
#endif