Java链表操作,
分享于 点击 41289 次 点评:37
Java链表操作,
package org.thinking_in_java.gz.link;
public class LinkList {
public Link<Integer> first;
public LinkList(){
this.first = null;
}
public void insertNode(Integer integer){
Link<Integer> node = new Link<Integer>(integer);
node.next = first;
first = node;
}
public boolean isEmpty(){
return (first == null);
}
public void delete(Integer data){
@SuppressWarnings("rawtypes")
Link current = first, previous = first;
while(Integer.parseInt(current.data.toString()) != data.intValue()){
if(current.next != null){
previous = current;
current = current.next;
}
}
if(current == first){
first = first.next;
}else{
previous.next = current.next;
}
}
public static void main(String[] args) {
LinkList list = new LinkList();
list.insertNode(12);
list.insertNode(13);
list.insertNode(14);
list.delete(12);
Link current = list.first;
while(current != null){
System.out.println(current.data);
current = current.next;
}
}
}
相关文章
- 暂无相关文章
用户点评