Singly linked list of basic algorithm series

A singly linked list is a chained access data structure. A set of storage units with arbitrary addresses are used to store the data elements in the linear list. The composition of each node is: element + pointer. The code is as follows:

public class Node{
    
    
	int data;
	Node next;
	public Node(int data){
    
    
		this.data=data;
	}
	public void *append*(Node node){
    
    	//追加节点
		Node currentNode=this;
		while(true){
    
    
			Node cnode=currentNode.next;
			currentNode=cnode;
			if(cnode==null){
    
    
				break;
			}
		}
		cnode.next=node;
		return this;
	}
	public Node next(){
    
    
		return this.next;
	}
	public int getData(){
    
    
		return this.data;
	}
	public boolean isLast(){
    
    
		return next==null;
	}
	public void removeNext(){
    
    
		Node nextnew=next.next;
		this.next=nextNew;
	}
	public void show(){
    
    
		Node currentNode=this;
		while(true){
    
    
			System.out.println(currentNode.data);
			currentNode=currentNode.next;
			if(currentNode==null){
    
    
				break;
			}
		}
	}
	public void after(Node node){
    
    	//插入节点
		Node nextNext=next;
		this.next=node;
		node.next=nextNext;
	}
}
 

Guess you like

Origin blog.csdn.net/langxiaolin/article/details/113460712