I have not the slightest idea how to remove a specific data from a stack. I tried to minhaPilha.remove();
and it did not work.
Console.WriteLine("<Pilha>");
Stack<string> minhaPilha = new Stack<string>();
Console.WriteLine("Para add itens, selecione X");
Console.WriteLine();
Console.WriteLine("Para remover itens, selecione Z");
Console.WriteLine();
Console.WriteLine("Caso queira remover um dado especifico digite W");
minhaPilha.Push("Primeira");
minhaPilha.Push("Segunda");
minhaPilha.Push("Terceira");
minhaPilha.Push("Quarta");
String opc = Console.ReadLine();
foreach (string carta in minhaPilha)
{
Console.WriteLine(carta);
}
if (opc == "Z")
{
Console.WriteLine();
minhaPilha.Pop();
foreach (string carta in minhaPilha)
{
Console.WriteLine(carta);
}
}
if (opc == "X")
{
Console.WriteLine("Digite aqui:");
minhaPilha.Push(Console.ReadLine());
Console.WriteLine();
foreach (string carta in minhaPilha)
{
Console.WriteLine(carta);
}
}
if (opc == "W")
{
Console.WriteLine();
minhaPilha.Pop();
foreach (string carta in minhaPilha)
{
Console.WriteLine(carta);
}
}
Console.WriteLine();
I know you can not do this on a stack. However, it was passed to me by a master: unstack, then remove the desired one and thus you stack again having taken the desired data.