public void Push(int _info) { if (isEmpty()) { topo = new NohPilha(_info); } else { NohPilha novoNoh = new NohPilha(_info, topo); topo = novoNoh; } }
public void Push_inv(int insertItem) { if (isEmpty()) { topo = new NohPilha(insertItem); } else { NohPilha n = new NohPilha(insertItem, topo); topo = n; } }
public int tamanho() { NohPilha n = topo; int i = 0; while (n != null) { i++; n = n.getNext(); } return(i); }
public void Pop(System.Windows.Forms.RichTextBox tbPop) { try { int valor = topo.getInfo(); topo = topo.getNext(); tbPop.Text = Convert.ToString(valor); } catch (NullReferenceException) { System.Windows.Forms.MessageBox.Show("Pilha vazia!!", "ERRO"); } }
public int Pop_inv() { if (isEmpty()) { Console.WriteLine("Pilha vazia!"); return(0); } else { int valor = topo.getInfo(); topo = topo.getNext(); return(valor); } }
public void Print(System.Windows.Forms.RichTextBox tbPilha) { tbPilha.Clear(); if (isEmpty()) { System.Windows.Forms.MessageBox.Show("Pilha vazia!!", "ERRO"); } else { NohPilha n = topo; while (n != null) { tbPilha.AppendText(Convert.ToString(n.getInfo()) + "\n"); n = n.getNext(); } } }
public void Menor(System.Windows.Forms.RichTextBox tbPilha) { if (isEmpty()) { System.Windows.Forms.MessageBox.Show("Pilha vazia!!", "ERRO"); } else { NohPilha n = topo; int menor = topo.getInfo(); while (n != null) { if (menor > n.getInfo()) { menor = n.getInfo(); } n = n.getNext(); } tbPilha.Text = Convert.ToString(menor); } }
public void Inverte(System.Windows.Forms.RichTextBox tbPilha) { if (isEmpty()) { System.Windows.Forms.MessageBox.Show("Pilha vazia!!", "ERRO"); } else { List <int> dados = new List <int>(); NohPilha n = topo; while (n != null) { dados.Add(n.getInfo()); n = n.getNext(); Pop_inv(); } for (int i = 0; i < dados.Count; i++) { Push_inv(dados[i]); } Print(tbPilha); } }
public Pilha() { topo = null; }
public void setNext(NohPilha _next) { next = _next; }
public NohPilha(int _info, NohPilha _next) { info = _info; next = _next; }
public NohPilha(int _info) { info = _info; next = null; }
public NohPilha() { info = 0; next = null; }