これが状況です。ユーザーがユーザー入力を介して team1 と team2 に名前を挿入すると、プログラムは TEAM1 と TEAM2 のすべての名前を表示します。Team1 の名前しか表示しないため、表示方法に問題があります。私がやりたいのは、チーム 1 とチーム 2 のすべての名前を表示することです。私はプログラミングが初めてで、学ぶのに本当に苦労しています。これまでの私のコードは次のとおりです。
class Node
{
protected String info;
protected Node next;
public Node(String value)
{
info = value;
next = null;
}
}
class LinkedList
{
private Node head;
private int count;
public LinkedList()
{
head = null;
count = 0;
}
public void insertteam1(String name)
{
Node b = new Node(name);
b.next = null;
count++;
if (head == null)
{
head = b;
return;
}
for(Node cur = head; cur != null; cur = cur.next)
{
if (cur.next == null)
{
cur.next = b;
return;
}
}
}
public void insertteam2(String name)
{
Node c = new Node(name);
c.next = null;
count++;
if (head == null)
{
head = c;
return;
}
for(Node cur = head; cur != null; cur = cur.next)
{
if (cur.next == null)
{
cur.next = c;
return;
}
}
}
public void displayTeamone()
{
for(Node cur = head; cur != null; cur = cur.next)
System.out.print(cur.info + " ");
System.out.println();
}
public void displayTeamtwo()
{
for(Node cur = head; cur != null; cur = cur.next)
System.out.println(cur.info + " ");
System.out.println();
}
}