编一个单链表的删除,查找,添加到尾部的程序遇到报错
import java.io.*;
class intsllnode{
public int info;
public intsllnode next;
public intsllnode (int i) {
this (i,null);
}
public intsllnode (int i,intsllnode n) {
info=i;next=n;
}
}
public class intsllist{
protected intsllnode head,tail;
private int input;
private BufferedReader buffer = new BufferedReader(
new InputStreamReader(System.in));
public intsllist() {
head=tail=null;
}
public boolean isempty() {
return head==null;
}
public void printall(){
for (intsllnode tmp=head;
tmp!=null;
tmp=tmp.next )
System.out.print(tmp.info+"");
}
public void delete (int el){
el=getint("I want delete this num");
if(head!=null)
if (el==head.info)
head=head.next;
else{
intsllnode pred=head,tmp=head.next;
for(;tmp!=null&&el!=tmp.info;
pred=pred.next,tmp=tmp=tmp.next)
if (tmp!=null)
pred.next=tmp.next;
}
}
public int find(int el){
el=getint("find this num");
intsllnode tmp=head;
for (;tmp!=null&&el!=tmp.info;
tmp=tmp.next)
if (tmp==null)
return null;
else return tmp.info;
}
public void addtotail(int el){
el=getint("insert a num");
if (!isempty()){
tail.next=new intsllnode(el);
tail=tail.next;
}
else head=tail=new intsllnode(el);
}
private int getint(String msg) {
System.out.print(msg + " ");
System.out.flush();
try {
input = buffer.readLine();
} catch(IOException io) {
}
return input;
}
public void run() {
while (true) {
char option = getString("\nEnter one of the following options:\n" +
"1. addtotail\n" +
"2. find\n" +
"3. delete\n" +"4.statues\n"+
"Your option:").charAt(0);
switch (option) {
case '1': addtotail(int el); break; // .class'expected 下面两个都是同样的错误 我是初学者 高手帮忙!!!
case '2': System.out.print(find(int el)); break;
case '3': delete(int el); break;
case '4': printall(); break;
case '5': return;
default: System.out.println("Wrong option, try again.");
}
}
}
public static void main(String args[]) {
(new intsllist()).run();
}
}