class Main {
public static void main(String[] args) {
}
}
class DoubleLinkedList{
private Node head = new Node(0,"");
public Node getNode(){
return head;
}
public void list(){
if(head.next == null){
System.out.println("链表为空");
return;
}
Node temp = head.next;
while(temp != null){
System.out.println(temp);
temp = temp.next;
}
}
public void add(Node node){
Node temp = head;
while(temp.next != null){
temp = temp.next;
}
temp.next = node;
node.pre = temp;
}
public void update(Node node){
if(head.next == null){
System.out.println("链表为空");
return;
}
Node temp = head.next;
while(temp != null){
if(temp.no == node.no){
temp.name = node.name;
System.out.println("修改成功");
return;
}
temp = temp.next;
}
System.out.println("修改失败");
}
public void del(int no){
if(head.next == null){
System.out.println("链表为空");
return;
}
Node temp = head.next;
boolean flag = false;
while(temp != null){
if(temp.no == no){
flag = true;
break;
}
temp = temp.next;
}
if(flag){
temp.pre.next = temp.next;
if(temp.next != null){
temp.next.pre = temp.pre;
}
}else{
System.out.printf("要删除的 %d 节点不存在\n",no);
}
}
}
class Node{
public int no;
public String name;
public Node next;
public Node pre;
public Node(int no,String name){
this.no = no;
this.name = name;
}
@Override
public String toString(){
return "Node[no=" + no + ",name=" + name + "]";
}
}