Java数据结构链表的插入与删除

  • 格式:doc
  • 大小:35.00 KB
  • 文档页数:6

下载文档原格式

  / 6
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
t1=read.nextLine();
list.findNo(t1);
}
else{System.out.println("您的输入有误");}
System.out.println("请您输入你要删除书的书名:");
String t2=null;
t2=read.nextLine();
list.delete(t2);
this.name=name;
this.price=price;
}
public Book(){};
public String getNo()
{
return no;
}
public String getName()
{
return name;
}
public int getPrice()
{
return price;
}
public String toString()
{
return no+" "+name+" "+price;
}
//重写tostring方法
} //book类,以及返回book的no,name,price
class Point
{
Book date=null;
Point next=null;
public Point(Book date)
{
this.date=date;
}
public Point getNext()
{
return next;
}
public void setNext(Point next)
{
this.next=next;
}
}
class Mylist
{
private Point head=null; //表头
private Point tail=null; //表尾
} //查找书编号
public void delete(String na1)
{
Point temp3=head.next;
while(temp3!=null&&temp3.date.getName()!=na1)
{
if(na1.equals(temp3.date.getName()))
{
//Point q=temp3.next;
{
this(date,null);
}
public Point(Book date,Point next)
{
this.date=date;
this.next=next;
}
public Point(){};
public Book getDate()
{
return date;
}
public void setDate(Book date)
String s=null;
int j=0,x=0;
while((s=inTwo.readLine())!=null)
{
if(x==0)
{
x=1;
System.out.println(s);
}
else
{
Book book1=new Book();
String ss[]=s.split("\\t");
{
Point w=head.next;
for(w=head.next;w!=null;w=w.next)
{
System.out.println(w.getDate()+" ");
}
}
}
book.price=readOne.nextInt();
list.insert(book, t3);
}
}
class Book
{
String no;
String name;
int price;
public Book(String no,String name,int price)
{
this.no=no;
temp3.next=temp3.next.next;
//delete q;
}
temp3=temp3.next;
}
System.out.println("删除完毕");
}//删除
public void insert(Book date,int n)
{
Point s=new Point(date); //这个地方不知道有没有的方法
x1=1;
}
temp1=temp1.next;
}
}
if(x1==0){System.out.println("没有找到您要找的书");}
System.out.println("查找完毕");
} //遍历查找方法书名
public void findNo(String no)
{
Point temp2=head.next;
int x2=0;
System.out.println("查询结果是:");
if(isEmpity())
{
System.out.println("链表是空的");
}
else
{
while(temp2!=null&&temp2.date.getNo()!=no)
{
//System.out.println("执行到了这一步");
{
temp=temp.getNext();
}
temp.setNext(tail);
length++;
} //添加
public void findName(String na)
{
int x1=0;
System.out.println("查询结果是:");
if(isEmpity())
{
System.out.println("链表是空的");
for(j=0;j<3;j++)
{
book1.no=ss[0];
book1.name=ss[1];
book1.price=Integer.parseInt(ss[2]);
} //这种字符串的解析不会用
list.addTail(book1);
}
}
inTwo.close();
inOne.close();
private int length;
int i;
Scanner read=new Scanner(System.in);
public Mylist()
{
this.head=new Point();
//tail=head;
length=0;
}
public boolean isELeabharlann Baidupity()
{
return head==null;
}
public void addHead(Book date)
{
head=new Point(date,head);
}
public void addTail(Book date)
{
Point tail=new Point(date,null);
Point temp=head;
while ( temp.getNext() != null)
import java.util.*;
import java.io.*;
public class zhangyue {
public static void main(String args[]){
File readFile=new File("F://book.txt");
Book book=new Book();
}catch(IOException e)
{System.out.println(e);}
list.output();
System.out.println("请输入你要查找的方法(1是按书名查找,2是按编号查找):");
int ch=0;
String t1=null;
Scanner readOne=new Scanner(System.in);
Scanner read=new Scanner(System.in);
Mylist list=new Mylist();
try
{
FileReader inOne=new FileReader(readFile);
BufferedReader inTwo=new BufferedReader(inOne);
}
else
{
Point temp1=head.next;
while(temp1!=null&&temp1.date.getName()!=na)
{
if(na.equals(temp1.date.getName()))
{
System.out.println(temp1.date.toString());
list.output();
System.out.println("请你输入你要插入的位置:");
System.out.println("请你输入书的信息:");
int t3=0;
t3=readOne.nextInt();
book.no=read.nextLine();
book.name=read.nextLine();
//s.date=date;
Point temp4=head.next;
for(int i=0;i<n;i++)
{
temp4=temp4.next;
}
s.next=temp4.next;
temp4.next=s;
System.out.println("插入完毕");
} //插入
public void output()
if(no.equals(temp2.date.getNo()))
{
System.out.println(temp2.date.toString());
x2=1;
}
temp2=temp2.next;
}
}
if(x2==0){System.out.println("没有找到您要找的书");}
System.out.println("查找完毕");
ch=readOne.nextInt();
if(ch==1)
{
System.out.println("请输入你要查找书的书名:");
t1=read.nextLine();
list.findName(t1);
}
else if(ch==2)
{
System.out.println("请输入你要查找书的编号:");