Cola Pila

Páginas: 2 (292 palabras) Publicado: 26 de mayo de 2012
IMPLEMENTACION DE COLA CON LISTAS
Clase List:
package Listas;
public class List {
private ListNode firstNode;
private ListNode lastNode;
private String name;

public List(){this("List");
}
public List(String listname){
name=listname;
firstNode=lastNode=null;
}
public void insertAtFront(Object insertItem){if(isEmpty())
firstNode=lastNode=new ListNode(insertItem);
else
firstNode=new ListNode(insertItem,firstNode);
}
public void insertAtBack(Object insertItem){if(isEmpty())
firstNode=lastNode=new ListNode(insertItem);
else
lastNode=lastNode.nextnode=new ListNode(insertItem);
}
public ObjectremoveFromFront()throws EmptyListException{
if(isEmpty())
throw new EmptyListException(name);
Object removedItem=firstNode.data;

if(firstNode==lastNode)firstNode=lastNode=null;
else
firstNode=firstNode.nextnode;
return removedItem;
}
public Object removeFromBack()throws EmptyListException{
if(isEmpty())throw new EmptyListException(name);

Object removedItem=lastNode.data;
if(firstNode==lastNode)
firstNode=lastNode=null;
else{ListNode current=firstNode;

while(current.nextnode!=lastNode)
current=current.nextnode;
lastNode=current;
current.nextnode=null;
}
returnremovedItem;
}
public boolean isEmpty(){
return firstNode==null;
}
public void print(){
if(isEmpty()){
System.out.printf("Empty%s\n",name);return;
}
System.out.printf("The %s is: ",name);
ListNode current=firstNode;
while(current!=null){
System.out.printf("%s ",current.data);...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • pilas y colas
  • Pilas y colas
  • Pilas y colas
  • Pilas y colas
  • Colas y pilas
  • Colas Pilas
  • Pila Y Cola
  • Pilas y Colas

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS