简体   繁体   English

如何比较Java中的两个链表节点?

[英]How does one compare two linked lists nodes in Java?

I am trying to write a searching algorithm to check one node in a linked integer list vs another node in that same list. 我正在尝试编写一种搜索算法,以检查链接的整数列表中的一个节点与同一列表中的另一个节点。

I think there seems to be a problem with the IF statement (data is in the list): 我认为IF语句似乎有问题(数据在列表中):

   LinkedList<Integer> listScore = new LinkedList<Integer>();
   int temp = 0;
   String temp2 = "";
   boolean flag = true;
   while (flag){
   flag = false;
   for (int j = 0; j < linebr; j++){
     if (listScore(j) < listScore(j+1)){
        System.out.println("Testing");
     }
}

I did originally try listScore[j] but I think there is something wrong with the way I have written it. 我最初确实尝试过listScore [j],但我认为我的编写方式有问题。 Any help or explanation as to why it doesent work would be Greatly appreciated!! 关于它为什么起作用的任何帮助或解释,将不胜感激!

Instead of listscore(j) and listscore(j+1) , what you need to get values inside LinkedLists is .get() . 要获取LinkedLists内的值,需要使用.get()而不是listscore(j)listscore(j+1) .get() So you should be using listscore.get(j) and listscore.get(j+1) . 因此,您应该使用listscore.get(j)listscore.get(j+1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM