Olá, tudo bom com você?
Espero que sim! Estou aqui para falar rapidamente de Pilhas e Filas. Bom, o C# possui no namespace System.Collections.Generic, duas classes genéricas, bem úteis, mas muito ignoradas: Stack<T> e Queue<T>.
O que você precisa saber de Queues e Stacks:
Queues implementas FIFO (First in, First Out), enquanto Stacks implementa LIFO (Last in, First Out).
Métodos e Propriedades mais relevantes
Comuns a Ambos
// // Summary: // Returns the object at the top of the System.Collections.Generic.Stack<T> or System.Collections.Generic.Queue<T> // without removing it. // // Returns: // The object at the top of the System.Collections.Generic.Stack<T> or System.Collections.Generic.Queue<T>. // // Exceptions: // System.InvalidOperationException: // The System.Collections.Generic.Stack<T> or The System.Collections.Generic.Queue<T> is empty. public T Peek();
// Summary: // Gets the number of elements contained in the System.Collections.Generic.Stack<T> or System.Collections.Generic.Queue<T>. // // Returns: // The number of elements contained in the System.Collections.Generic.Stack<T> or System.Collections.Generic.Queue<T>. public int Count { get; }
System.Collections.Generic.Queue<T>
// // Summary: // Adds an object to the end of the System.Collections.Generic.Queue<T>. // // Parameters: // item: // The object to add to the System.Collections.Generic.Queue<T>. The value can // be null for reference types. public void Enqueue(T item);
// // Summary: // Removes and returns the object at the beginning of the System.Collections.Generic.Queue<T>. // // Returns: // The object that is removed from the beginning of the System.Collections.Generic.Queue<T>. // // Exceptions: // System.InvalidOperationException: // The System.Collections.Generic.Queue<T> is empty. public T Dequeue();
System.Collections.Generic.Stack<T>
// // Summary: // Removes and returns the object at the top of the System.Collections.Generic.Stack<T>. // // Returns: // The object removed from the top of the System.Collections.Generic.Stack<T>. // // Exceptions: // System.InvalidOperationException: // The System.Collections.Generic.Stack<T> is empty. public T Pop();
// // Summary: // Inserts an object at the top of the System.Collections.Generic.Stack<T>. // // Parameters: // item: // The object to push onto the System.Collections.Generic.Stack<T>. The value // can be null for reference types. public void Push(T item);
Bom, era somente isso que eu queria passar. Vale a pena dar uma olhada em outras classes disponíveis no namespace System.Collections aconselho olhar:
System.Collections.Concurrent.ConcurrentQueue<T> System.Collections.Concurrent.ConcurrentStack<T> System.Collections.Generic.SortedSet<T> System.Collections.Generic.SortedList<TKey, TValue> System.Collections.Generic.LinkedList<T>
todos estão nos assemblies mscorlib ou System.
Era só isso!
Grande abraço!
0 comentários