编写一个单链表类的成员函数,实现在非递减的有序链表中插入一个值为x的数据元素,并使单链表仍然保持有序的操作。
public class LinkList implements IList {
public Node head;
public LinkList() {
head = new Node();//Node是标红的,显示Cannot instantiate the type Node
}
public void clear() {
head.next = null;//所有的next都是标红的,显示next cannot be resolved or is not a field
head.next = 0;
}
public boolean isEmpty() {
// TODO Auto-generated method stub
return head.next == null;
}
public int lenght() {
// TODO Auto-generated method stub
int i = 0;
Node p = head.next;
while (p != null) {
i++;
p = p.next;
}
return i;
}
//实现类
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
int n = 5;
LinkList N = new LinkList(); //LinkList()标红
Scanner sc = new Scanner(System.in);
for(int i = 0; i < n;i++){
int temp = sc.nextInt();
N.insert(i,temp);
}
}
System.out.println("当前链表为:"); //" ; "标红 out.println中间的点标红
N.display(); //“ ;”标红
System.out.println("请输入待插入数字x");
int x = new Scanner(System.in).nextInt();
N.orderInsert(x);
System.out.print("当前链表为:");
N.display();
Node是标红的,显示Cannot instantiate the type Node
所有的next都是标红的,显示next cannot be resolved or is not a field
实现类中的下面语句的“ ;”都是标红的
我删除重写后依旧标红
不知道你这个问题是否已经解决, 如果还没有解决的话:有定义Node类吗,而且类定义中有构造函数么