Пример #1
0
        static void Main(string[] args)
        {
            IStackVagon train = new StackVagon1();

            /*train.Push(new Vagon { Type = 1 });
            *  train.Push(new Vagon { Type = 0 });
            *  train.Push(new Vagon { Type = 1 });
            *  train.Push(new Vagon { Type = 0 });
            *  train.Push(new Vagon { Type = 1 });
            *  train.Push(new Vagon { Type = 0 });
            *  train.Push(new Vagon { Type = 0 });
            *  train.Push(new Vagon { Type = 0 });*/
            //train = new TrainFactory().GetStackVagonFromFile(@"d:\Temp\train.txt");
            train = new TrainFactory().GetRandStackVagon(20);
            train.Print();
            IStackVagon cargo = new StackVagon();
            IStackVagon pass  = new StackVagon2();

            while (!train.IsEmpty)
            {
                if (train.Peek().Type == 1)
                {
                    pass.Push(train.Pop());
                }
                else
                {
                    cargo.Push(train.Pop());
                }
            }
            pass.Print();
            cargo.Print();
        }
Пример #2
0
        public IStackVagon GetRandStackVagon(int n)
        {
            IStackVagon stackVagon = new StackVagon1();
            Random      r          = new Random();

            for (int i = 0; i < n; i++)
            {
                stackVagon.Push(GetVagon(r.Next(0, 2)));
            }
            return(stackVagon);
        }
Пример #3
0
        public IStackVagon GetStackVagonFromFile(string fileName)
        {
            IStackVagon  stackVagon = new StackVagon1();
            StreamReader sr         = new StreamReader(fileName);
            string       strVagons  = sr.ReadToEnd();

            string[] masStrVagonType = strVagons.Split(';');
            for (int i = 0; i < masStrVagonType.Length; i++)
            {
                stackVagon.Push(new Vagon {
                    Type = int.Parse(masStrVagonType[i])
                });
            }
            return(stackVagon);
        }