예제 #1
0
        public void insereInicio(int data)
        {
            NohLista noh = new NohLista(data);

            if (isEmpty())
            {
                inicio = fim = noh;
            }
            else
            {
                inicio.setPrevio(noh);
                noh.setNext(inicio);
                inicio = noh;
            }
        }
예제 #2
0
        public void insereFim(int data)
        {
            NohLista noh = new NohLista(data);

            if (isEmpty())
            {
                inicio = fim = noh;
            }
            else
            {
                fim.setNext(noh);
                noh.setPrevio(fim);
                fim = noh;
            }
        }
예제 #3
0
 public void remove(int noh)
 {
     bool achou = false;
     if (isEmpty())
     {
         throw new Exception();
     }
     for (NohLista aux = inicio; aux != null; aux = aux.getNext())
     {
         if (aux.getData() == noh)
         {
             if (aux == inicio)
             {
                 inicio = inicio.getNext();
                 inicio.setPrevio(null);
             }
             else if (aux == fim)
             {
                 fim = fim.getPrevio();
                 fim.setNext(null);
             }
             else
             {
                 aux.getPrevio().setNext(aux.getNext());
                 aux.getNext().setPrevio(aux.getPrevio());
             }
             achou = true;
             break;
         }
     }
     if (!achou)
     {
         Console.Error.WriteLine("Item não encontrado");
         throw new Exception();
     }
 }
예제 #4
0
 public Lista()
 {
     inicio = fim = null;
 }
예제 #5
0
 public void setNext(NohLista next)
 {
     this.next = next;
 }
예제 #6
0
 public void setPrevio(NohLista previo)
 {
     this.previo = previo;
 }
예제 #7
0
 public NohLista(int data, NohLista previo, NohLista next)
 {
     this.previo = previo;
     this.data   = data;
     this.next   = next;
 }
예제 #8
0
 public NohLista(int data)
 {
     previo    = next = null;
     this.data = data;
 }
예제 #9
0
 public NohLista()
 {
     previo = next = null;
     data   = 0;
 }