📄 assignment3.java
字号:
public class Assignment3
{
public static void main(String args[])
{
Tokenizer a = new Tokenizer();
NodeList list_1 = new NodeList();
String s = a.nextWord();
while (s!="")
{
if (s.length()>2)
list_1.insertLast(s);
s = a.nextWord();
}
System.out.println("Total number of words of more than two characters = "+list_1.size());
NodeList list_2 = new NodeList();
int num = list_1.size();
Position pos1 = list_1.first();
Position pos2 = null;
while (!(list_1.isLast(pos1)))
{
pos2 = list_1.after(pos1);
String str1 =(String)pos1.element();
//System.out.println(str1);
char chr1 = str1.charAt(0);
if ((chr1!='A') && (chr1!='E') && (chr1!='I') && (chr1!='O') && (chr1!='U')) //begin with a consonant
{
list_1.remove(pos1);
list_2.insertLast(str1);
}
pos1 = pos2;
}
pos1 = list_1.last();//check the last word in list1;
String str1 =(String)pos1.element();
//System.out.println(str1);
char chr1 = str1.charAt(0);
if ((chr1!='A') && (chr1!='E') && (chr1!='I') && (chr1!='O') && (chr1!='U')) //begin with a consonant
{
list_1.remove(pos1);
list_2.insertLast(str1);
}
//System.out.println(list_1.size());
System.out.println("Total number of words starting with a consonant = "+list_2.size());
BinarySearchTree bst = new BinarySearchTree(new Comparator());
pos1 = list_1.first();
while (!(list_1.isLast(pos1)))
{
bst.insertItem((String)pos1.element(),new Integer(1));
pos1 = list_1.after(pos1);
}
bst.insertItem(pos1.element(),new Integer(1));
PrintWordTree.inorder(bst.T, bst.T.root());
System.out.println("Total number of different words = "+bst.size());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -