mplement a(n) (unbalanced) binary search tree nonstd::MultiSet class which behav
ID: 3598529 • Letter: M
Question
mplement a(n) (unbalanced) binary search tree nonstd::MultiSet class which behaves similarly to std::multiset (Links to an external site.)Links to an external site.. Note that you will not have to implement iterators, which is why insert is void.
Any members or methods in the private sections can be modified however you like, as long as it's still in the spirit of the assignment. For example, you may use regular pointers instead of std::unique_ptr but don't use an std::multiset as part of your implementation.
Note that in a more realistic implementation, you might not have getters and setters for the MultiSet<T>::Node's left and right children but I have them in this assignment so I can more easily grade your code without needing to care whether you use regular pointers or something else.
multiset.h
Explanation / Answer
package com;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
public class ListExample extends JFrame
{
BufferedReader br = null;
FileReader fr = null;
List<String> ListA=new ArrayList<String>();
List<String> ListE=new ArrayList<String>();
List<String> ListI=new ArrayList<String>();
List<String> ListO=new ArrayList<String>();
List<String> ListU=new ArrayList<String>();
DefaultListModel<String> l1 = new DefaultListModel<>();
DefaultListModel<String> l2 = new DefaultListModel<>();
DefaultListModel<String> l3 = new DefaultListModel<>();
DefaultListModel<String> l4 = new DefaultListModel<>();
DefaultListModel<String> l5 = new DefaultListModel<>();
JFrame f= new JFrame();
private JButton jButton1 = new JButton("Add");
ListExample(){
try{
fr = new FileReader("D:\test.txt.txt");
br = new BufferedReader(fr);
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
if(sCurrentLine.charAt(0)=='A' || sCurrentLine.charAt(0)=='a'){
System.out.println("A : " + sCurrentLine);
ListA.add(sCurrentLine);
}
else if(sCurrentLine.charAt(0)=='E' || sCurrentLine.charAt(0)=='e'){
System.out.println("E : " + sCurrentLine);
ListE.add(sCurrentLine);
}
else if(sCurrentLine.charAt(0)=='I' || sCurrentLine.charAt(0)=='i'){
System.out.println("I : " + sCurrentLine.charAt(0));
ListI.add(sCurrentLine);
}
else if(sCurrentLine.charAt(0)=='O' || sCurrentLine.charAt(0)=='o'){
System.out.println("O : " + sCurrentLine.charAt(0));
ListO.add(sCurrentLine);
}
else if(sCurrentLine.charAt(0)=='U' || sCurrentLine.charAt(0)=='u'){
System.out.println("U : " + sCurrentLine.charAt(0));
ListU.add(sCurrentLine);
}
}
JList<String> list1 = new JList<>(l1);
JList<String> list2 = new JList<>(l2);
JList<String> list3 = new JList<>(l3);
JList<String> list4 = new JList<>(l4);
JList<String> list5 = new JList<>(l5);
list1.setBounds(30, 35, 115, 200);
f.add(list1);
list2.setBounds(180, 35, 110, 195);
f.add(list2);
list3.setBounds(330, 35, 100, 195);
f.add(list3);
list4.setBounds(460, 30, 95, 200);
f.add(list4);
list5.setBounds(590, 35, 110, 190);
f.add(list5);
jButton1.setSize(70,20);
jButton1.setVisible(true);
jButton1.setText("Add");
f.add(jButton1);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
f.setSize(816, 537);
f.setLayout(null);
f.setVisible(true);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
if (fr != null)
fr.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
private void jButton1_actionPerformed(ActionEvent e) {
System.out.println("Click Me");
for(String str:ListA){
l1.addElement(str);
}
for(String str:ListE){
l2.addElement(str);
}
for(String str:ListI){
l3.addElement(str);
}
for(String str:ListO){
l4.addElement(str);
}
for(String str:ListU){
l5.addElement(str);
}
JList<String> list1 = new JList<>(l1);
JList<String> list2 = new JList<>(l2);
JList<String> list3 = new JList<>(l3);
JList<String> list4 = new JList<>(l4);
JList<String> list5 = new JList<>(l5);
list1.setBounds(30, 35, 115, 200);
f.add(list1);
list2.setBounds(180, 35, 110, 195);
f.add(list2);
list3.setBounds(330, 35, 100, 195);
f.add(list3);
list4.setBounds(460, 30, 95, 200);
f.add(list4);
list5.setBounds(590, 35, 110, 190);
f.add(list5);
}
public static void main(String args[])
{
new ListExample();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.