Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Hi, my name is Alex. This is an assignment that is due tonight at 11:59 pm. This assignment was supposed to be due next Friday, but my teacher changed the date at the last minute. I tried to get help from other sites and none have been able to help me. You are my last hope.

String as Singly Linked List

In many programming languages, the String class is typically implemented as an array of characters. Some other languages, such as Haskell, Erlang, and a few other functional programming languages, however, implement strings as Singly Linked List (SLL) of characters. Compared with the array implementations, the SLL ones are very easy for pattern matching because of the recursive structure of linked list. Let’s don’t worry about recursion in this assignment.

In this assignment, you will implement a SLLString class using SLL. Your SLLString class will include the following members:

  • SLLString(); //Default constructor
  • SLLString(const string& other); //copy constructor taking a C++ string as parameter.
  • ~SLLString(); // destructor.
  • SLLString(const SLLString& other); //copy constructor taking another SLLString
  • SLLString& operator=(const SLLString& other); // assignment constructor
  • int length(); // get length of this string.
  • SLLString& operator+= (const SLLString& other); // concatenation
  • char& operator[](const int n); //get character at index n.
  • int findSubstring(const SLLString& substring); // find the index of the first occurrence of substring in the current string. Returns -1 if not found.
  • void erase(char c); //erase all occurrences of character c from the current string.
  • support cout <<
  • Node* head; // the head pointer to the SLL.

Each Node object should contain a char data type and a next pointer to Node.

Here are the sample usages:

int main(){

SLLString str("Hello world!");

SLLString newStr = new SLLString;

newStr = str;

newStr += SLLString(" CS@BC");

newStr[6] = ‘W’;

cout << newStr << endl; // Hello World! CS@BC

cout << newStr.length() << endl; //18

int loc = newStr.findSubstring("World");

cout << loc << endl; // 6

newStr.erase(‘l’); //erase the letter l.

cout << newStr << endl; // Heo Word! CS@BC

newStr.erase(‘C’);

cout << newStr << endl; // Heo Word! S@B

}

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education