Last active
April 12, 2021 18:46
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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