package e_link.B;
/**
* 单链表:针对key查询,或者删除
* @author Administrator
*
*/
public class LinkListApp {
public static void main(String[] args) {
LinkList theList=new LinkList();
theList.insertFirst(1, 10);
theList.insertFirst(2, 20);
theList.insertFirst(3, 30);
theList.insertFirst(4, 40);
theList.insertFirst(5, 50);
theList.insertFirst(6, 60);
theList.insertFirst(7, 70);
theList.displaysList();
theList.find(1).displaysLink();
theList.delete(7).displaysLink();
System.out.println();
theList.displaysList();
}
}package e_link.B;
public class LinkList {
private Link first;
public LinkList() {
first = null;
}
public void insertFirst(int id, double dd) {
Link newLink = new Link(id, dd);
newLink.next = first;
first = newLink;
}
/*
* 根据指定key查询连接点
*/
public Link find(int key) {
Link current = first;
while (current.iDate != key) {
if (current.next == null)
return null;
else
current = current.next;
}
return current;
}
/*
* 根据key删除指定的连接点
*/
public Link delete(int key) {
Link current = first;// 当前
Link previous = first;// 前一个
while (current.iDate != key) {
if (current.next == null)
return null;
else {
previous = current;
current = current.next;
}
}
if (current == first)
first = current.next;
else
previous.next = current.next;
return current;
}
public void displaysList(){
Link current=first;
while(current.next!=null){
current.displaysLink();
current=current.next;
System.out.println();
}
}
}package e_link.B;
public class Link {
public int iDate;
public double dDate;
public Link next;
public Link(int id,double dd){
iDate=id;
dDate=dd;
}
public void displaysLink(){
System.out.print("{"+iDate+","+dDate+"}");
}
}
/**
* 单链表:针对key查询,或者删除
* @author Administrator
*
*/
public class LinkListApp {
public static void main(String[] args) {
LinkList theList=new LinkList();
theList.insertFirst(1, 10);
theList.insertFirst(2, 20);
theList.insertFirst(3, 30);
theList.insertFirst(4, 40);
theList.insertFirst(5, 50);
theList.insertFirst(6, 60);
theList.insertFirst(7, 70);
theList.displaysList();
theList.find(1).displaysLink();
theList.delete(7).displaysLink();
System.out.println();
theList.displaysList();
}
}package e_link.B;
public class LinkList {
private Link first;
public LinkList() {
first = null;
}
public void insertFirst(int id, double dd) {
Link newLink = new Link(id, dd);
newLink.next = first;
first = newLink;
}
/*
* 根据指定key查询连接点
*/
public Link find(int key) {
Link current = first;
while (current.iDate != key) {
if (current.next == null)
return null;
else
current = current.next;
}
return current;
}
/*
* 根据key删除指定的连接点
*/
public Link delete(int key) {
Link current = first;// 当前
Link previous = first;// 前一个
while (current.iDate != key) {
if (current.next == null)
return null;
else {
previous = current;
current = current.next;
}
}
if (current == first)
first = current.next;
else
previous.next = current.next;
return current;
}
public void displaysList(){
Link current=first;
while(current.next!=null){
current.displaysLink();
current=current.next;
System.out.println();
}
}
}package e_link.B;
public class Link {
public int iDate;
public double dDate;
public Link next;
public Link(int id,double dd){
iDate=id;
dDate=dd;
}
public void displaysLink(){
System.out.print("{"+iDate+","+dDate+"}");
}
}