class Link {
public String reName;//收件人姓名
public String seName;//发件人姓名
public String emType;//邮件类型:普通,特快,汇款等等
public String dDay;
//收件日期,四位数年份+两位数月份+两位数日期,如19900203
public String sign;//邮件是否被人签收
public Link next;
public Link (String rename,String sename,String emtype,String day,String sign0){
reName=rename;
seName=sename;
emType=emtype;
dDay=day;
sign=sign0;
}
public void displayLink(){
System.out.println("收件人是:"+reName+" 发件人是:"+seName+" 邮件类型是:"+emType+" 于"+dDay+"收件 已签收?" +sign);
}
}
public class LinkList {
private Link first;
public LinkList(){
first=null;
}
//添加邮件信息
public void insertFirst(String rename,String sename,String emtype,String day,String sign0)
{
Link newLink=new Link(rename,sename,emtype,day,sign0);
newLink.next=first;
first=newLink;
}
public Link find(String name)//根据收件人姓名进行查找
{
Link current =first;
while(current.reName!=name)
{
if (current.next==null)
return null;
else
current=current.next;
}
return current;}
public Link delete(String name)
//根据收件人姓名,对整份文件进行销毁删除
{
Link current=first;
Link previous=first;
while(current.reName!=name)
{
if (current.next==null)
return null;
else{
previous=current;
current=current.next;}
}
if(current==first)
first=first.next;
else
previous.next=current.next;
return current;
}
public void displayList(){
System.out.println("校园收发室目前添加的的一些邮件信息如下");
System.out.println();
Link current=first;
while(current!=null){
current.displayLink();
current=current.next;
}
System.out.println("");
}
}
import java.io.*;
class LinkListApp
{
static String rename;
static String sename;
static String emtype;
static String day;
static String sign0;
public static void main (String []args){
System.out.print("请输入收件人:");
try{
rename= getString();
}catch(Exception e){
System.out.println("请输入收件人!");
}
System.out.print("请输入发件人:");
try{
sename= getString();
}catch(Exception e){
System.out.println("请输入发件人!");
}
System.out.print("请输入邮件类型:");
try{
emtype= getString();
}catch(Exception e){
System.out.println("请输入邮件类型!");
}
System.out.print("请输入收件日期:");
try{
day= getString();
}catch(Exception e){
System.out.println("请输入收件日期!");
}
System.out.print("是否签收? :");
try{
sign0= getString();
}catch(Exception e){
System.out.println("请输入是否已经签收!");
}
System.out.println("邮件信息添加成功!");
LinkList theList=new LinkList();
theList.insertFirst(rename,sename,emtype,day,sign0);
theList.displayList();
String key=null;
System.out.print("请输入要查询的收件人:");
try{
key= getString();
}catch(Exception e){
System.out.println("请输入要查询的收件人!");
}
Link f=theList.find(key);
if(f!=null)
System.out.println("该邮件的信息是:"+f.reName);
else
System.out.println("该邮件无法找到");
详细解决方案
链表的,可以插入但是查找不到,哪里出有关问题了
热度:90 发布时间:2016-04-23 01:00:48.0
相关解决方案