示例#1
0
        public static void driver()
        {
            string s      = "stone";
            string target = "money";

            dw   = DictionaryWords.getInstance(s.Length);
            dict = dw.getDict();
            Stopwatch sw = new Stopwatch();

            sw.Start();
            Stack <string> stk = GenerateLadder(s, target);

            if (stk.Count <= 0)
            {
                Console.WriteLine("No ladder found");
            }
            else
            {
                Console.WriteLine("Words in ladder: ");
                foreach (string str in stk)
                {
                    Console.WriteLine(str);
                }
            }

            sw.Stop();
            Console.WriteLine("Time taken with stacks and queues = {0} ms", sw.ElapsedMilliseconds);
        }
示例#2
0
 public static DictionaryWords getInstance(int length)
 {
     if (dw == null)
     {
         lock (syncRoot)
         {
             if (dw == null)
             {
                 dw = new DictionaryWords(length);
             }
         }
     }
     return(dw);
 }
 public static DictionaryWords getInstance(int length)
 {
     if (dw == null)
     {
         lock (syncRoot)
         {
             if (dw == null)
             {
                 dw = new DictionaryWords(length);
             }
         }
     }
     return dw;
 }
示例#4
0
        public static void driver()
        {
            string s = "stone";
            string target = "money";
            dw = DictionaryWords.getInstance(s.Length);
            dict = dw.getDict();
            Stopwatch sw = new Stopwatch();
            sw.Start();
            Stack<string> stk = GenerateLadder(s, target);
            if (stk.Count <= 0)
                Console.WriteLine("No ladder found");
            else
            {
                Console.WriteLine("Words in ladder: ");
                foreach (string str in stk)
                {
                    Console.WriteLine(str);
                }
            }

            sw.Stop();
            Console.WriteLine("Time taken with stacks and queues = {0} ms", sw.ElapsedMilliseconds);
        }
示例#5
0
 public GraphLadder(string source)
 {
     root = new Node(source);
     dict = DictionaryWords.getInstance(source.Length).getDict();
 }