Estructuras

Páginas: 4 (787 palabras) Publicado: 9 de junio de 2012
226

CHAPTER 5

Linked Lists

current.previous.next = current.next; if(current==last) last = current.previous; else // last item? // old previous <-- last // not last // old previous <-- old nextcurrent.next.previous = current.previous;

The doublyLinked.java Program
Listing 5.8 shows the complete doublyLinked.java program, which includes all the routines just discussed. LISTING 5.8 ThedoublyLinked.java Program

// doublyLinked.java // demonstrates doubly-linked list // to run this program: C>java DoublyLinkedApp ////////////////////////////////////////////////////////////////class Link { public long dData; // data item public Link next; // next link in list public Link previous; // previous link in list //------------------------------------------------------------public Link(long d) // constructor { dData = d; } // ------------------------------------------------------------public void displayLink() // display this link { System.out.print(dData + “ “); } //------------------------------------------------------------} // end class Link //////////////////////////////////////////////////////////////// class DoublyLinkedList { private Link first; // refto first item private Link last; // ref to last item // ------------------------------------------------------------public DoublyLinkedList() // constructor { first = null; // no items on list yetlast = null; }

Doubly Linked Lists

227

LISTING 5.8

Continued

// ------------------------------------------------------------public boolean isEmpty() // true if no links { returnfirst==null; } // ------------------------------------------------------------public void insertFirst(long dd) // insert at front of list { Link newLink = new Link(dd); // make new link if( isEmpty() ) // ifempty list, last = newLink; // newLink <-- last else first.previous = newLink; // newLink <-- old first newLink.next = first; // newLink --> old first first = newLink; // first --> newLink } //...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Estructura
  • Estructura
  • Estructura
  • Estructuras
  • Estructuras
  • Estructuras
  • Estructuras
  • estructuras

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS