예제 #1
0
        // метод интерфейса IEnumerable<T>, который унаследовал от интерфейса IEnumerable
        public IEnumerator <T> GetEnumerator()
        {
            MyQueue <T> cur = end;

            while (cur != null)
            {
                yield return(cur.data);

                cur = cur.next;
            }
        }
예제 #2
0
        // метод интерфейса IEnumerable
        IEnumerator IEnumerable.GetEnumerator()
        {
            MyQueue <T> ts = end;

            while (ts != null)
            {
                yield return(ts.data);

                ts = ts.next;
            }
        }
예제 #3
0
        public void CopyTo(T[] array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentException("Пустой массив!");
            }
            MyQueue <T> cur = end;

            for (int i = arrayIndex; i < array.Length; i++)
            {
                array[i] = cur.data;
                cur      = cur.next;
            }
        }
예제 #4
0
        public object Clone()
        {
            if (end == null)
            {
                return(null);
            }
            MyQueue <T> cur  = end;
            MyQueue <T> copy = new MyQueue <T>();

            foreach (T it in cur)
            {
                copy.Add(it);
            }
            return(copy);
        }
예제 #5
0
        public bool Remove(T item)
        {
            if (count == 1 && end.data.Equals(item))
            {
                Clear();
                return(true);
            }
            if (item == null)
            {
                throw new Exception("Невозможно удалить пустой элемент");
            }
            int index = IndexOf(item);

            if (index == -1)
            {
                return(false);
            }
            if (index == count - 1 && end.data.Equals(item))
            {
                end = end.next;
                return(true);
            }
            MyQueue <T> cur = end;

            for (int i = 0; i < count - index; i++)
            {
                if (cur.next.data.Equals(item))
                {
                    if (cur.next == begin)
                    {
                        cur.next = null;
                        begin    = cur;
                        count--;
                        return(true);
                    }
                    cur.next = cur.next.next;

                    count--;
                    return(true);
                }

                cur = cur.next;
            }
            return(false);
        }
예제 #6
0
        public int IndexOf(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("Поиск пустого элемента карается по закону, но это не точно..");
            }
            MyQueue <T> cur   = this.end;
            int         index = Count;

            while (cur != null)
            {
                if (cur.data.Equals(item))
                {
                    index--; return(index);
                }
                index--;
                cur = cur.next;
            }
            return(-1);  // если не найден
        }
예제 #7
0
 private static void RandomGen(ref MyQueue <Transport> list, int n)
 {
     for (int i = 0; i < n; i++)
     {
         if (i % 4 == 0)
         {
             list.Add(new Transport(rand.Next(1, 800), rand.Next(1, 1000)));
         }
         else if (i % 3 == 0)
         {
             list.Add(new Avtomobile(MasName[rand.Next(0, 4)], rand.Next(1, 300), rand.Next(1, 10)));
         }
         else if (i % 2 == 0)
         {
             list.Add(new Rain(rand.Next(1, 100), rand.Next(1, 400), rand.Next(1, 1000)));
         }
         else
         {
             list.Add(new Express(MasNameOfExpress[rand.Next(0, 4)], rand.Next(1, 100), rand.Next(1, 800), rand.Next(1, 1000)));
         }
     }
 }
예제 #8
0
 public virtual void Add(T item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("Попытка ввода пустого элемента");
     }
     if (end == null)
     {
         MyQueue <T> cur = new MyQueue <T>();
         cur.data = item;
         end      = cur;
         begin    = end;
         count++;
         return;
     }
     else
     {
         MyQueue <T> nwE = new MyQueue <T>();
         nwE.data = item;
         nwE.next = end;
         end      = nwE;
         count++;
     }
 }
예제 #9
0
        static void Main(string[] args)
        {
            List <MyQueue <Transport> > list1 = new List <MyQueue <Transport> >();

            bool ok = true;

            Console.WriteLine("Введите количество вокзалов в городе");
            int n1 = Input.IntCheckConsole();

            for (int i = 0; i < n1; i++)
            {
                Console.WriteLine($"Введите количество транспорта {i + 1} -го вокзала");
                int n2 = Input.IntCheckConsole();
                MyQueue <Transport> cris = new MyQueue <Transport>();
                RandomGen(ref cris, n2);
                list1.Add(cris);
            }
            while (ok)
            {
                Console.WriteLine(MainMenu);
                Console.WriteLine("Введите значение: ");
                int  vib    = Input.IntCheckConsole();
                int  q      = 0;
                bool onLinq = true;
                switch (vib)
                {
                case 1:
                    foreach (var it in list1)
                    {
                        Output.ShowRed($"Вокзал {q + 1}");
                        ShowQueue(it);
                        q++;
                    }
                    break;

                case 2:
                    onLinq = LinqOrExten();
                    if (onLinq)
                    {
                        Request4LINQ(list1);
                    }
                    else
                    {
                        Request4EXTEN(list1);
                    }
                    break;

                case 3:
                    onLinq = LinqOrExten();
                    if (onLinq)
                    {
                        Request1LINQ(list1);
                    }
                    else
                    {
                        Request1EXTEN(list1);
                    }
                    break;

                case 4:
                    Console.WriteLine("Введите номер вокзала");
                    int k = Input.IntCheckConsole();
                    while (k < 1 || k > n1 + 1)
                    {
                        Console.WriteLine("Введите номер вокзала");
                        k = Input.IntCheckConsole();
                    }
                    onLinq = LinqOrExten();
                    if (onLinq)
                    {
                        Request2LINQ(list1, k - 1);
                    }
                    else
                    {
                        Request2EXTEN(list1, k - 1);
                    }
                    break;

                case 5:
                    onLinq = LinqOrExten();
                    if (onLinq)
                    {
                        Request3LINQ(list1);
                    }
                    else
                    {
                        Request3EXTEN(list1);
                    }
                    break;

                case 6:
                    onLinq = LinqOrExten();
                    if (onLinq)
                    {
                        Request5LINQ(list1);
                    }
                    else
                    {
                        Request5EXTEN(list1);
                    }
                    break;

                case 7:
                    onLinq = LinqOrExten();
                    if (onLinq)
                    {
                        Request6LINQ(list1);
                    }
                    else
                    {
                        Request6EXTEN(list1);
                    }
                    break;

                default:
                    Output.ShowRed("Неопознанное значение!");
                    break;
                }
            }
        }
예제 #10
0
 public void Clear()
 {
     end   = null;
     begin = null;
     count = 0;
 }