Hyperlink java在链表末尾插入

Hyperlink java在链表末尾插入,hyperlink,insert,eclipselink,insertion,Hyperlink,Insert,Eclipselink,Insertion,最后插入的代码不起作用 请帮帮我 如何在链表的末尾插入元素 在java中,链表真的很混乱,请大家回答我的问题 在我有其他疑问之前,我已经澄清了,谢谢你这么做 请再次回答我如何在我的代码列表末尾插入元素 导入java。实用扫描仪; 类节点 { int i,q; 节点下一步; 节点前置; } 类链接{ 公共静态void main(字符串参数[]) { linkk l=新的linkk(); l、 op(); int user=0; while(用户!=10) {扫描器a=新扫描器(System.in

最后插入的代码不起作用 请帮帮我 如何在链表的末尾插入元素 在java中,链表真的很混乱,请大家回答我的问题 在我有其他疑问之前,我已经澄清了,谢谢你这么做 请再次回答我如何在我的代码列表末尾插入元素

导入java。实用扫描仪;
类节点
{
int i,q;
节点下一步;
节点前置;
}
类链接{
公共静态void main(字符串参数[])
{
linkk l=新的linkk();
l、 op();
int user=0;
while(用户!=10)
{扫描器a=新扫描器(System.in);
如果(用户==1)
{
System.out.println(“\n输入数据\n”);
l、 创建(a.nextInt());
}System.out.println(“\n1.create link\n2.insert start\n3.insert middle\n4.insert end\n5.delete data\n6.reverse”);
user=a.nextInt();
}
如果(用户==2)
l、 insertbeg();
如果(用户==3)
l、 insertmid();
如果(用户==4)
l、 insertend();
如果(用户==5)
l、 del();
如果(用户==6)
l、 反向();
如果(用户==7)
l、 显示();
}
}
linkk类
{  
节点temp4;
int ch,add,cnt=0,t=0,b;
节点p=新节点();
节点q;
最后一个节点;
node first=新节点;
公共布尔值为空()
{
返回first==null;
}
public void insertbeg()
{
}
公共void insertmid()
{
}
公共void insertend()
{//这是我的代码,但不起作用
p=新节点();
System.out.println(“输入数据”);
p、 i=b.nextInt();
温度=第一;
while(临时下一步!=null)
温度=下一个温度;
下一个温度=p;
p、 next=null;
cnt++;
}
公屋
{
} 
公共无效反向()
{
}
公共空间显示()
{
}
公共void创建(int val)
{   
第一,i=val;
first.next=null;
cnt++;
}
公共图书馆
{
}
公共图书馆(op)
{
}
}
仅此而已。按此处指定添加(对象)


迭代到最后一个节点,然后使用最后一个节点的下一个指针添加新节点

尝试以下方法:

public void insertend(node newNode) {
    node nextNode = headNode;
    while (nextNode.next != null) {
        nextNode = nextNode.next;
    }
    nextNode.next = newNode;
}

public void insertend(){p=new node();System.out.println(“输入数据”);p.i=b.nextInt();temp=first;while(temp.next!=null)temp=temp.next;temp.next=p;p.next=null;cnt++;}任何人都可以键入正确的代码,在列表末尾插入我的pg吗?为什么你自己“搜索”列表的末尾?在中,有一个addLast方法,它将一个新项追加到列表的末尾。(它还有一个addFirst方法)没有位置参数的add()方法也会添加到列表的末尾。主席先生,headnode与我使用rgtif im使用public void insertend(new newnode)时使用的第一个节点相同,然后在调用我应该使用的内容时,这是您可以调用的方式<代码>节点n=新节点();节点i=10;节点q=20;插入(n)但是插入端是无效的,先生,我应该更改它吗?这是返回类型,我们不会更改它。