Question: Your overall task for Part B is to read in a string from the console, convert it into an instance of MyString implemented now as

Your overall task for Part B is to read in a string from the console, convert it into an instance of MyString
implemented now as a singly linked list of characters, and re-implement a subset of the standard string
operations.
Requirements
Complete the MyString class that is partially defined below.
public class MyString : ICloneable, IComparable {
private class Node {
public char item;
public Node next;
// Constructor (1 mark)
public Node (...){...}
}
private Node front; // Reference to the first (header) node
private int length; // Number of characters
// Initialize an instance of MyString based on the given character array A (4 marks)
public MyString (char[] A){...}
// Create and return a clone of the current instance (5 marks)
public object Clone(){...}
// Compare the current instance of MyString with obj and return a -1,0 or +1
// if the current string comes before, at or after obj in alphabetical order (5 marks)
public int CompareTo(object obj){...}
// Return the index of the first occurrence of c; otherwise return -1(2 marks)
public int IndexOf(char c){...}
// Remove all occurrences of c (4 marks)
public void Remove (char c){...}
// Return true if obj is both of type MyString and the same as the current instance;
// otherwise return false (2 marks)
// Hint: Use CompareTo
public override bool Equals (object obj){...}
// Print the current instance of MyString (2 marks)
public void Print(){...}
}
The main program will present a list of options to the user that exercises each of the methods above. To
display and allow the user to choose among multiple instances of MyString, store the instances of
MyString in an instance of List. For a 5 bonus marks, keep the list in alphabetical order.

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 Programming Questions!