0

String と Int を含むリンク リストがあります。int にアクセスするにはどうすればよいですか? たとえば、ユーザーは Football と Basketball を選択します (文字列 = Int が 11 の "Football"。Int が 5 の "Basketball")。Football と Basketball を呼び出すと、ディスプレイには 16 が表示されます。

これが私のコードです:

public StringNode_1(String s, Integer i, StringNode_1 sn) {
  Sport= s;
  Amount= i;
  next = sn;

メイン プログラムの場合:

public void addNode(String s, int i){
  StringNode_1 curnode;
  curnode = head;
  while(curnode.next != null) {
    curnode = curnode.next;

  }
  curnode.next = new StringNode_1(s,i,null);
}

この:

SLinkedList_1 thelist = new SLinkedList_1();
thelist.addFirst("Cricket", 5);
thelist.addNode("Football", 11);
thelist.addNode("Basketball", 5);
printList(thelist);
4

0 に答える 0