コード例 #1
0
        static void Main(string[] args)
        {
            var input = "to be or not to - be - - that - - - is";
            var s     = input.Split(' ');
            var queue = new StackQueue <string>();

            foreach (var n in s)
            {
                if (!n.Equals("-"))
                {
                    queue.Enqueue(n);
                }
                else
                {
                    Console.WriteLine(queue.Dequeue());
                }
            }
        }
コード例 #2
0
 private static StackQueue <Item> OneStep(StackQueue <Item> q)
 {
     if (q.isRecopying && !q.H.IsEmpty() && !q.T.IsEmpty())
     {
         q.nowcopying++;
         q.HH.Push(q.T.Pop());
         q.Hr.Push(q.H.Pop());
     }
     else if (q.isRecopying && q.H.IsEmpty() && !q.T.IsEmpty())
     {
         q.isRecopying = true;
         q.HH.Push(q.T.Pop());
     }
     else if (q.isRecopying && q.H.IsEmpty() && q.T.IsEmpty() && q.nowcopying > 1)
     {
         q.isRecopying = true;
         q.nowcopying--;
         q.HH.Push(q.Hr.Pop());
     }
     else if (q.isRecopying && q.H.IsEmpty() && q.T.IsEmpty() && q.nowcopying == 1)
     {
         q.isRecopying = false;
         q.nowcopying--;
         q.HH.Push(q.Hr.Pop());
         q.H  = q.HH;
         q.T  = q.TT;
         q.HH = new Stack <Item>();
         q.TT = new Stack <Item>();
         q.Hr = new Stack <Item>();
         q.h  = new Stack <Item>();
     }
     else if (q.isRecopying && q.H.IsEmpty() && q.T.IsEmpty() && q.nowcopying == 0)
     {
         q.isRecopying = false;
         q.H           = q.HH;
         q.T           = q.TT;
         q.HH          = new Stack <Item>();
         q.TT          = new Stack <Item>();
         q.Hr          = new Stack <Item>();
         q.h           = new Stack <Item>();
     }
     return(q);
 }