봄 축제가 다가 오면서 프로젝트가 끝났고 우리는 모두 새해를 위해 집으로 돌아 가기를 기다리고 있습니다. 아래는 편집자가 귀하를 위해 데이터 구조를 연구하는 편집자에 대한 관련 지식입니다. 링크 된 목록은 자주 사용되는 데이터 구조입니다. 이제 다음과 같이 내 자신의 구현을 보여 드리겠습니다. 조언을 받으시면 Great Master에 오신 것을 환영합니다.
첫 번째 버전에는 마지막 노드가 없으며 매번 루트 노드에서 트래버스가 시작됩니다.
public class linkedlist <e> {private node head; public linkedlist () {} public e getfirst () {if (head == null) {return null;} return head.value;} public linkedlist <e> addfirst (e e) {head.pre = new Node (e, null, head); head.pre. addnode (e e) {node lst = head; if (lst == null) {this.head = new node (e, null, null); this;} else {while (true) {if (lst.next == null) {} else {lst = lst.next;} lst.next = new Node (e, l, null); this;}} public linkedlist <e> 제거 (e e) {node lst = head; if (lst == null) {새 nullpointerexception ( "링크 사전 목록은 비어 있습니다.");} else {while (true) {if (eequals (lst.value)) {//이 요소를 제거합니다. if (lst.pre! = null) {lst.pre.next = lst.next;} if (lst.next! = null) {lst.next.pre = lst.pre;} lst = null; break;} lst = lst.next;}}}}}@rebudridepublic string tosstring () {stringbufer re ritidepublic string tosstring () StringBuffer ( "["); node lst = this.head; while (lst! = null) {buff.append (lst.value+","); lst = lst.next;} return buff.substring (0, buff.length () -1)+"];}/** Node Class Node {public node e; node pree; 값, 노드 프리, 노드 다음) {this.value = value; this.pre = pre; this.next = next;}}}두 번째 버전에는 마지막 노드가 있습니다
public class linkedlist <e> {private node head; private node last; public linkedlist () {} public e getfirst () {if (head == null) {return null;} return head.value;} public e getlast () {if (last == null) {return null; value;} public inlink;} e) {head.pre = 새 노드 (e, null, head); head = head.pre; return this;} public linkedlist <e> addnode (e e) {node lst = last; if (lst == null) {//이 링크 목록이 비어있는 경우,이 링크 목록이 비어 있습니다. this.head = this.last; return this;} else} else {while (while) {if (lst.next == null) {// break;} else {lst = lst.next;}} lst.next = new Node (e, lst, null); last = lst.next; return this;}} public linkedlist <e) lst = head; if (lst == null) {throw new nullpointerexception ( "linkedlist는 비어 있습니다.");} else {while (true) {if (e.equals (lst.value)) {//이 요소를 제거합니다 if (lst.pre! = null) {lst.pre.next = lst.next;} if (lst.next! = null) {lst.next.pre = lst.pre;} lst = null; break;} lst = lst.next;}}}}}@rebudridepublic string tosstring () {stringbufer re ritidepublic string tosstring () StringBuffer ( "["); node lst = this.head; while (lst! = null) {buff.append (lst.value+","); lst = lst.next;} return buff.substring (0, buff.length () -1)+"];}/** Node Class Node {public node e; node pree; 값, 노드 프리, 노드 다음) {this.value = value; this.pre = pre; this.next = next;}}}참고 : 위의 두 버전 중 어느 것도 멀티 스레딩에서 사용을 고려하지 않습니다.
위는 편집자가 소개 한 양방향 링크 목록 (두 버전) 구현에 대한 관련 지식입니다. 나는 그것이 당신에게 도움이되기를 바랍니다.