public void StackTest() { Lists.Stack <string> MyStack = new Lists.Stack <string>(); MyStack.Push("First"); MyStack.Push("Second"); MyStack.Push("Third"); var i = MyStack.Pop(); var j = MyStack.Pop(); var k = MyStack.Pop(); }
/// <summary> /// A depth first search traversal of the graph, starting from a specified vertex. /// Returns the visited vertices of the graph. /// </summary> public virtual IEnumerable <T> DepthFirstWalk(T source) { if (VerticesCount == 0) { return(new ArrayList <T>()); } else if (!HasVertex(source)) { throw new Exception("The specified starting vertex doesn't exist."); } var visited = new HashSet <T>(); var stack = new Lists.Stack <T>(VerticesCount); var listOfNodes = new ArrayList <T>(VerticesCount); stack.Push(source); while (!stack.IsEmpty) { var current = stack.Pop(); if (!visited.Contains(current)) { listOfNodes.Add(current); visited.Add(current); foreach (var adjacent in Neighbours(current)) { if (!visited.Contains(adjacent)) { stack.Push(adjacent); } } } } return(listOfNodes); }