日期:2014-05-17  浏览次数:20931 次

C# 1,3,5,7 排列组合(3位) 非递归
//深度优先
class Program
    {
        static void Main(string[] args)
        {
            int[] number = new int[] { 1, 3, 5, 7 };
            List data = new  List();
            Stack openStack = new Stack();
            Tree root = new Tree();
            Tree parent =root;
            while (true)
            {
             
                if (parent.GetDeep() == 4)
                {
                    parent.printf();
                   
                }
                else
                {
                   var tempSon= number.ToList();
                   foreach (var item in tempSon)
                   {
                       Tree Node = new Tree();
                       Node.NodeData = item;
                       Node.Parent = parent;
                       openStack.Push(Node);
                   }
                }
               if (openStack.Count == 0)[color=darkred][/color]
                    break;
               var itemData= openStack.Pop();
               parent = itemData;

            }
            System.Console.Read();

        }
        public static void printf(List data)
        {
            string d="";