Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Last active April 12, 2021 18:46
Show Gist options
  • Save luisdeol/009b4c472feb7c24afeaebe3fdc7d3dd to your computer and use it in GitHub Desktop.
Save luisdeol/009b4c472feb7c24afeaebe3fdc7d3dd to your computer and use it in GitHub Desktop.
Artigo Estrutura de Dados - Parte #1 - Pilha para Histórico de Alterações
using System;
using System.Collections.Generic;
namespace DataStructuresCsharp
{
public class HistoricoOperacoes
{
private Stack<string> _historico;
public HistoricoOperacoes(string nomeUsuario)
{
NomeUsuario = nomeUsuario;
_historico = new Stack<string>();
}
public string NomeUsuario { get; private set; }
public void Adicionar(string nome)
{
_historico.Push(nome);
}
public void Desfazer()
{
Console.WriteLine($"Última operação desfeita.");
_historico.Pop();
}
public string RetornarUltimaOperacao()
{
var ultimaOperacao = _historico.Peek();
return ultimaOperacao;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment