The chain storage structure of linear table is to store data elements in several storage units with scattered addresses. Logically, the adjacent data elements are not necessarily adjacent in physical location. Therefore, additional information must be used to represent the order relationship between data elements. The storage unit that stores a data element is called a Node. A Node includes at least a data domain and an address domain. The data domain stores data, the address domain stores the precursor or the successor, and the single chain table is linked by nodes.
Basic operations of single chain table: add, find, modify, delete
public class Node<T>{ private T date; private Node<T> nextnode; } public class Link<T> { private Node<T> head; public Link(T date) { this.date = date; } public Link(T date,Link<T> nextnode) { this.date = date; this.nextnode =nextnode; } public T getDate() { return date; } public void setDate(T date) { this.date = date; } public Link<T> getNextnode() { return nextnode; } public void setNextnode(Link<T> nextnode) { this.nextnode = nextnode; } @Override public String toString() { return "Link [date=" + date + ", nextnode=" + nextnode + "]"; } //increase public void add(Node<T> node,Node<T> nextNode) { if (node!=null) { node.nextnode = nextNode; }else { System.out.println("Insert success"); } } //lookup public void Search(Node<T> node,T date) { int i = 0; if (node ==null) { System.out.println("Linked list is empty."); }else { if (node.date == date) { System.out.println(i); i++; Search(node.nextnode, date);//Continue to find other }else { i++; Search(node.nextnode, date); } } } //modify public void Update(Node<T> node,T date,T ud) { if (node ==null) { System.out.println("Linked list is empty."); }else { if (node.date == date) { node.date =ud; Update(node.nextnode, date, ud); }else { Update(node.nextnode, date, ud); } } } //delete public void Delete(Node<T> node,Node<T> nodetwo) { if (node ==null) { System.out.println("Linked list is empty."); }else { if (node.nextnode == nodetwo ) { node.nextnode =nodetwo.nextnode; nodetwo.nextnode = null; }else { Delete(node.nextnode,nodetwo); } } } }