Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Stack<Node<T>> PRO (Node<T> node, System.Predicate<Node<T>> match)
- {
- var fila = new Stack<Node<T>> ();
- Node<T> recursivo (Node<T> ESTADO)
- {
- if (match (node)) return node;
- else
- {
- //REMOVER_DA_PILHA (esTADO);
- fila.Pop ();
- foreach (Node<T> child in node.Children)
- {
- fila.Push (child);
- }
- }
- while (fila.Count > 0)
- {
- #if DEBUG
- System.Diagnostics.Debug.WriteLine (node.ToString ());
- #endif
- if (match (fila.First ()))
- {
- return fila.First ();
- }
- fila.Pop ();
- }
- return null;
- }
- recursivo (node);
- return fila;
- }
- public Node<T> LARGURA (Node<T> node, System.Predicate<Node<T>> match)
- {
- var fila = new Stack<Node<T>> ();
- var current = node;
- do
- {
- #if DEBUG
- System.Diagnostics.Debug.WriteLine (current.ToString ());
- #endif
- if (match (current)) return current;
- else
- {
- foreach (Node<T> child in current.Children)
- fila.Push (child);
- }
- if (fila.Count == 0) return default (Node<T>);
- current = fila.Pop ();
- } while (true);
- }
- public class ItsAlmostAStack<T>
- {
- private List<T> items = new List<T> ();
- public void Push (T item)
- {
- items.Add (item);
- }
- public T Pop ()
- {
- if (items.Count > 0)
- {
- T temp = items[items.Count - 1];
- items.RemoveAt (items.Count - 1);
- return temp;
- }
- else
- return default (T);
- }
- public void Remove (int itemAtPosition)
- {
- items.RemoveAt (itemAtPosition);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement