Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
LinkedList.java 941 Bytes
Copy Edit Raw Blame History
stefanzan authored 2020-10-27 09:35 . [add] java version code
public class LinkedList <E> {
private Node head;
public LinkedList() {
head = null;
}
public void addToFront(E item) {
Node node = new Node(item);
if (this.head == null) {
this.head = node;
} else{
Node temp = head;
this.head = node;
this.head.next = temp;
}
}
public void addToRear(E item) {
Node newNode = new Node(item);
if (this.head == null) {
this.head = newNode;
} else {
Node temp = this.head;
while(temp.next != null){
temp = temp.next;
}
temp.next = newNode;
}
}
public void print() {
Node temp = this.head;
while(temp.next != null){
System.out.print(temp.item + " -> ");
temp = temp.next;
}
System.out.println(temp.item);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化