singly linked list as a data structure to re-implement the Java String class., Exercises of Data Structures and Algorithms

use singly linked list as a data structure to re-implement the Java String class.

Typology: Exercises

2018/2019

Uploaded on 11/14/2019

shaikha-alqadheeb
shaikha-alqadheeb 🇸🇦

2 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lab 2
The goal of this lab is to use singly linked list as a data structure to re-implement the Java String class.
The new class will be named SLLString.
1. Define the self-referential class CharNode that will be used to define a Linked List of characters.
2. Define the class SLLString with a head, tail, and length data fields.
3. Write a default constructor for the class SLLString.
4. Write a second constructor for the class SLLString that takes a String object as an argument and
initializes the class from the String object.
5. Write the following methods for the class SLLString:
char charAt(int index)
Returns the char value at the specified index.
Int indexOf(int ch, int fromIndex)
Returns the index within this string of the first occurrence of the specified
character, starting the search at the specified index.
Int indexOf(String str, int fromIndex)
Returns the index within this string of the first occurrence of the specified
substring, starting at the specified index.
Int lastIndexOf(int ch, int fromIndex)
Returns the index within this string of the last occurrence of the
specified character, searching backward starting at the specified
index.
Int lastIndexOf(String str, int fromIndex)
Returns the index within this string of the last occurrence of the
specified substring, searching backward starting at the specified
index.
SLLString replaceFirst(String regex, String replacement)
Replaces the first substring of this string that matches the given
regular expression with the given replacement.
SLLString[] split(String regex, int limit)
Splits this string around matches of the given regular expression.
SLLString substring(int beginIndex, int endIndex)
Returns a new string that is a substring of this string.
pf2

Partial preview of the text

Download singly linked list as a data structure to re-implement the Java String class. and more Exercises Data Structures and Algorithms in PDF only on Docsity!

Lab 2

The goal of this lab is to use singly linked list as a data structure to re-implement the Java String class.

The new class will be named SLLString.

1. Define the self-referential class CharNode that will be used to define a Linked List of characters.

2. Define the class SLLString with a head, tail, and length data fields.

3. Write a default constructor for the class SLLString.

4. Write a second constructor for the class SLLString that takes a String object as an argument and

initializes the class from the String object.

5. Write the following methods for the class SLLString:

char charAt(int index) Returns the char value at the specified index.

Int (^) indexOf (int ch, int fromIndex)

Returns the index within this string of the first occurrence of the specified

character, starting the search at the specified index.

Int (^) indexOf (String str, int fromIndex)

Returns the index within this string of the first occurrence of the specified

substring, starting at the specified index.

Int lastIndexOf(int ch, int fromIndex) Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.

Int lastIndexOf(String str, int fromIndex) Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.

SLLString replaceFirst(String regex, String replacement) Replaces the first substring of this string that matches the given regular expression with the given replacement.

SLLString[] split(String regex, int limit) Splits this string around matches of the given regular expression.

SLLString substring(int beginIndex, int endIndex) Returns a new string that is a substring of this string.

SLLString toUpperCase() Converts all of the characters in this String to upper case using the rules of the default locale.

SLLString trim() Returns a copy of the string, with leading and trailing whitespace omitted.