?? singlelink.java
字號:
package com.itjob.data;
public class SingleLink {
public Node head;
public Node rear;
public Node parrent;
public void add(Object data){
if (head == null){
head = new Node(data);
rear = head;
}else{
rear.next = new Node(data);
rear = rear.next;
}
}
public boolean delete(Object data){
Node result = find(data);
if (result == null){
return false;
}else{
if (result == head){
head = head.next;
if (head == null){
rear = null;
}
}else{
parrent.next = result.next;
if (parrent.next == null){
rear = parrent;
}
}
return true;
}
}
public boolean update(Object oldData,Object newData){
Node temp = find(oldData);
if (temp == null){
return false;
}else{
temp.data = newData;
return true;
}
}
public Node find(Object data){
Node temp = head;
parrent = head;
while (temp != null){
if (temp.data.equals(data)){
return temp;
}
parrent = temp;
temp = temp.next;
}
return null;
}
public String toString(){
StringBuilder result = new StringBuilder("[");
Node temp = head;
while (temp != null){
if (temp == rear){
result.append(temp.data);
}else{
result.append(temp.data + ",");
}
temp = temp.next;
}
result.append("]");
return result.toString();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -