Question: Create an application that will keep track of several groups of strings. Each string will be a member of exactly one group. We would like


Create an application that will keep track of several groups of strings. Each string will be a member of exactly one group. We would like to be able to see whether two strings are in the same group as well as perform a union of two groups. Use a linked structure to represent a group of strings. Each node in the structure contains a string and a reference to another node in the group. For example, the group t"a", "b", "d'', ''e'' is represented by the following structure One string in each group d" in our example is in a node that has a null reference. That is, it does not reference any other node in the structure. This string is the representative string of the group. Create the class GroupHolder to represent all of the groups and to perform operations on them. It should have the private instance variable items to hold the nodes that belong to all of the groups. The nodes within each group are linked together as described previously. Make items an instance of Array List whose base type is GroupNode, where GroupNode is a private inner class of Group Holder. GroupNode has the following private instance variables: data a string link a reference to another node in the group, or null Define the following methods in the class GroupHolder: addltem(s0 adds a string s to an empty group. First search items for s, if you find s, do nothing: if you do not find s, create a new GroupNode new group will contain only the item s getRepresentative(s) returns the representative string for the group containing s. To find the representative string, search items for s. If you do not find s, return null. If you find s, follow links until you find a null reference. The string in that node is the representative string for the group get AllRepresentatives returns an instance of at contains the representative strings of all the groups in this instance of GroupHolder
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
