/// <summary> /// Desempilha um elemento. /// </summary> /// <returns>O objeto que estava no topo da pilha, ou null, se a pilha estiver vazia</returns> public Dados pop() { Elemento aux = this.topo.prox; if (aux != null) { this.topo.prox = aux.prox; aux.prox = null; if (aux == this.fundo) { this.fundo = this.topo; } return(aux.d); } else { return(null); } }
/// <summary> /// Desenfileira o primeiro objeto da fila. /// </summary> /// <returns>Retorna um objeto ou null, caso a fila esteja vazia</returns> public Dados desenfileirar() { Elemento aux = this.prim.prox; if (aux != null) { this.prim.prox = aux.prox; if (aux == this.ult) { this.ult = this.prim; } else { aux.prox = null; } this.quantidade -= 1; return(aux.d); } else { return(null); } }
public Elemento(Dados dado) { this.d = dado; this.prox = null; }
public ListaCircular() { this.atual = new Elemento(null); this.prox = this.atual; }
/// <summary> /// Construtor. Cria uma pilha vazia com sentinela. /// </summary> public Pilha() { this.topo = new Elemento(null); this.fundo = this.topo; }
/// <summary> /// Construtor. Cria uma lista vazia com sentinela. /// </summary> public Lista() { this.prim = new Elemento(null); this.ult = this.prim; }
/// <summary> /// Construtor. Cria uma fila vazia com sentinela. /// </summary> public Fila() { this.quantidade = 0; this.prim = new Elemento(null); this.ult = this.prim; }