0

我有一个带有 String 和 Int 的链表。我怎样才能访问int?例如,用户选择 Football 和 Basketball (String = "Football" with Int as 11. and "Basketball" with Int 5)。如果我调用 Football and 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