public class BST<Key extends Comparable<Key>, Value> {
private Node root; // root of BST
private class Node {
private Key key; // sorted by key
private Value val,val2,val3; // associated data
private Node left, right; // left and right subtrees
private Node mid;
private int N; // number of nodes in subtree
SD sd=new SD();
Queue<Value> ele = new Queue<Value>();
public Node(Key key, Value val,Value val2,Value val3, int N) {
this.key = key;
this.sd.one = val;
this.sd.two=val2;
this.sd.three=val3;
this.N = N;
}
}
private SD get(Node x, Key key) {
if (x == null) return null;
int cmp = key.compareTo(x.key);
if (cmp < 0) return get(x.left, key);
else if (cmp > 0) return get(x.right, key);
else {
if(notmid(x.mid))
return x.sd;
else
return getmid(x.mid,key);
}
}
private SD getmid(Node x, Key key){
x.sd.one=x.ele.dequeue();
x.sd.two=x.ele.dequeue();
x.sd.three=x.ele.dequeue();
return get(x, key);
}
public void put(Key key, Value val,Value val2, Value val3) {
if (val == null) { delete(key); return; }
root = put(root, key, val,val2,val3);
assert check();
}
private Node put(Node x, Key key, Value val,Value val2,Value val3) {
if (x == null)
{
x.sd.one=val;
x.sd.two=val2;
x.sd.three=val3;
return new Node(key, val,val2,val3, 1);
}
int cmp = key.compareTo(x.key);
if (cmp < 0) x.left = put(x.left, key, val,val2,val3);
else if (cmp > 0) x.right = put(x.right, key, val,val2,val3);
else {
x.mid=putsame(x.mid,key,val,val2,val3);
}
x.N = 1 + size(x.left) + size(x.right);
return x;
}
private Node putsame(Node x,Key key,Value val,Value val2,Value val3){
x.ele.enqueue(val);
x.ele.enqueue(val2);
x.ele.enqueue(val3);
x.key=key;
return x;
}
private boolean notmid(Node x){
return x.mid.ele.isEmpty();
}
public void SearchData(int index,ArrayList<Student> x,String input){
int size=x.size();
String[] studentid=new String[size],
studentname=new String[size],
coursecode=new String[size],
grade=new String[size];
Integer[] code=new Integer[size];
String[] tem=new String[3];
SD wer=new SD();
BST<String, String> st = new BST<String,String>();
//size记录数组的大小
String v1,v2,v3;
//将Student类中的数据导出
for(int i=0;i<size;i++){
studentid[i]=x.get(i).StudentID;
studentname[i]=x.get(i).StudentName;
coursecode[i]=x.get(i).ScoreCode;
code[i]=x.get(i).Code;
}
//获取按钮中index,排序选中的元素,并将其他元素也进行排序
//Quik.sort中需要排序的为第一个元素,第二第三第四为其他附属元素,跟着第一个元素位置的改动而改动
switch(index){
case 1:
//选中StudnetID进行排序,
Quick.sort(studentid,studentname,coursecode,code);
for(int i=0;i<x.size();i++) grade[i]=code[i].toString();
for (int i = 0; i<x.size(); i++) {
String key = studentid[i];
v1=studentname[i];
v2=coursecode[i];
v3=grade[i];
st.put(key,v1,v2,v3);
}
wer=st.get(input);
System.out.println("StudentID is :"+input+" StudentName is:"+wer.one+" soursecode is :"+wer.two+" score is :"+wer.three);
break;}
}
------解决思路----------------------
用Java自带的ArrayList,不需要自己造轮子。
------解决思路----------------------
你的main () 方法 贴一下 a......