2
I have no idea how to remove a specific data from a stack. I tried to perform the minhaPilha.remove();
and nothing went right.
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’t do this in a pile. However, I was passed by a master: desempilhe, then remove the desired and so you stack again having removed the desired dice.
What do you call "specific data"? Do you want to remove an item that is not the last one? Do you know what a stack is? You know this can’t be done to her?
– Maniero
Yes, I know it is not possible. However, I was given this headache by a master and the logic he gave was. Desempilhe, then remove the desired and so you stack again having removed the desired data.
– user31194
When it is so, put all possible information in the question.
– Maniero
Thanks, bigown... starting now on the overflow.... Again thank you, vlh
– user31194