我首先要说的是我是一个Java(/编程)新手,这是我在网站上的第一个问题.
刚学会了如何使用递归节点在Java中创建有序列表.一切都很简单,直到我遇到这个练习,要求我编写一个方法,将每个节点中包含的任何值加倍.这是我试写的代码:
public class ListaInteri<E extends Integer>
{
private NodoLista inizio;
// Private inner class each instance of these has a raw type variable and a
// ref
// to next node in the list
private class NodoLista
{
E dato;
NodoLista pros;
}
// method that adds whatever is meant by x to the begging of the list
public void aggiungi(E x)
{
NodoLista nodo = new NodoLista();
nodo.dato = x;
if (inizio != null)
nodo.pros = inizio;
inizio …Run Code Online (Sandbox Code Playgroud)