À medida que o festival da primavera se aproxima, o projeto terminou e todos estamos esperando para voltar para casa para o ano novo. Abaixo está o conhecimento relevante do editor que estuda a estrutura de dados para você. A lista vinculada é uma estrutura de dados que é frequentemente usada. Agora vou mostrar minha própria implementação da seguinte maneira. Bem -vindo ao grande mestre para conselhos.
A primeira versão não tem o último nó e começa a atravessar o nó raiz toda vez
public class LinkedList <E> {private node head; public linkedList () {} public e getfirst () {if (head == null) {return null;} retorna cabeça.value;} public linkList <e> addfirst (e e) {head.pre = new node (e, null, null); addNode (e e) {nó lst = head; if (lst == null) {this.head = new Node (e, nulo, nulo); retorna tis;} else {while) {if (lst.next == null) {break;} else {lst = lst.next;}}}} Este;}} public linkedList <E> remover (e e) {node lst = head; if (lst == null) {tiro new nullPointerException ("o linkList está vazio.");} else {while) if (lst.pre! Stringbuffer ("["); nó lst = this.head; while (lst! = Null) {buff.append (lst.value+","); lst = lst.next;} retornar buff.substring (0, buff.length ()-1)+"]";}/** node informação*/privado; valor, nó pre, nó a seguir) {this.value = value; this.preA segunda versão tem o último nó
public class LinkedList <E> {nó privado Head; nó privado último; public linkedList () {} public e getfirst () {if (head == null) {return null;} retornar head.value;} public e getLast () {if (last == null) {return null}; e) {head.pre = novo nó (e, null, cabeça); head = head.pre; return this;} public linkedList <e> addNode (e e) {node lst = last; if (lst == null) {// se o último nó estiver vazio, esta lista de links está vazia. this.head = this.Last; retorne tis;} else {while (true) {if (lst.Next == null) {// break;} else {lst = lst.next;}} lst.next = novo nó (e, lst, null); last.next; retorno; lst = head; if (lst == null) {tiro new nullPointerException ("o linkedlist está vazio.");} else {while (true) {if (e.equals (lst.value)) {// remova este elemento if (lst.pre! Stringbuffer ("["); nó lst = this.head; while (lst! = Null) {buff.append (lst.value+","); lst = lst.next;} retornar buff.substring (0, buff.length ()-1)+"]";}/** node informação*/privado; valor, nó pre, nó a seguir) {this.value = value; this.preNota: Nenhuma das duas versões acima considera o uso em Multithreading.
O exposto acima é o conhecimento relevante sobre a implementação de listas vinculadas bidirecionais (duas versões) apresentadas a você pelo editor. Espero que seja útil para você.