import java.util.*;
class Node{
int val;
Node next;
Node(int val){
this.val=val;
this.next=null;
}
public String toString() {
return String.format("Node(%d)",val);
}
}
public class MyLinkedList {
public static void main(String[] args) {
Node head=null;
head=pushFront(head,1);
head=pushFront(head,2);
head=pushFront(head,3);
print(head);
}
public static Node pushFront(Node head,int val){
Node node=new Node(val);
node.next=head;
return node;
}
private static void print(Node head) {
for(Node cur=head;cur!=null;cur=cur.next) {
System.out.println(cur);
}
}
private Node popFront(Node head) {
if(head==null) {
System.err.println("空链表无法作删除");
return;
}
return head.next;
}
private Node popBack(Node head) {
if(head==null) {
System.err.println("空链表无法删除");
return;
}
if(head.next==null) {
return null;
}
else {
Node lastSecond=head;
while(lastSecond.next.next!=null) {
lastSecond=lastSecond.next;
}
lastSecond.next=null;
}
}
private static Node pushBack(Node head,int val) {
Node node=new Node(val);
if(head==null) {
return node;
}
else {
Node last=head;
while(last.next!=null) {
last=last.next;
}
last.next=node;
return head;
}
}
}