Java 如何返回符号表中的最大键

Java 如何返回符号表中的最大键,java,linked-list,Java,Linked List,这是我到目前为止所做的,但我不确定我是否做对了。我无法返回无序链接列表的maxKey: public class LinkedListST<Key extends Comparable<Key>, Value> { private Node first; private class Node { private Key key; private Value val; private Node next;

这是我到目前为止所做的,但我不确定我是否做对了。我无法返回无序链接列表的maxKey:

public class LinkedListST<Key extends Comparable<Key>, Value> {
    private Node first;
    private class Node {
        private Key key;
        private Value val;
        private Node next;

    public Node(Key key, Value val, Node next)  {
        this.key  = key;
        this.val  = val;
        this.next = next;
    }
}

public Key maxKey (Key key) {
    Node currentNode = null;    //current node we are on
    if (first == null)
        return null;
    for(currentNode = first; currentNode != null; currentNode = currentNode.next){

        }
    return null;
}
}
公共类LinkedList{
私有节点优先;
私有类节点{
私钥;
私人价值;
私有节点下一步;
公共节点(键、值val、节点下一步){
this.key=key;
this.val=val;
this.next=next;
}
}
公钥maxKey(Key-Key){
Node currentNode=null;//我们所在的当前节点
if(first==null)
返回null;
对于(currentNode=first;currentNode!=null;currentNode=currentNode.next){
}
返回null;
}
}

您需要比较所有键并找到最大的键

public Key maxKey () {
    Node currentNode = null;    //current node we are on
    if (first == null)
        return null;
    Key<Comparable> max = first.key;
    do {
      currentNode = currentNode.next;
      if (currentNode == null) break;
      if (currentNode.key.compareTo(max) > 0) {
        max = currentNode.key;
      }
    while (true);
    return max;
}
公钥maxKey(){
Node currentNode=null;//我们所在的当前节点
if(first==null)
返回null;
Key max=first.Key;
做{
currentNode=currentNode.next;
如果(currentNode==null)中断;
如果(currentNode.key.compareTo(最大值)>0){
max=currentNode.key;
}
虽然(正确);
返回最大值;
}

如果没有参数,代码会是什么样子?调整以显示没有参数的方法…这是相同的代码,因为我最初从未使用过
键(ZS,160)“我实际上不明白这意味着什么