Пример #1
0
        public void RemoveItem(int index)
        {
            lock (this)
            {
                while (this.Counter == 0)
                {
                    if (Program.stop)
                    {
                        return;
                    }
                    Monitor.Wait(this);
                }
                if (data[index].Year > 2000)
                {
                    Car       car       = data[index];
                    string    hash      = this.CalculateHash(car);
                    CarResult carResult = new CarResult(car, hash);
                    Program.resultMonitor.AddItemSorted(carResult);
                }

                Console.WriteLine($"removed car {data[index].Brand}");
                for (int i = index; i < Counter - 1; i++)
                {
                    data[i] = data[i + 1];
                }
                this.SetCount(Counter - 1);
            }
        }
Пример #2
0
        public void AddItemSorted(CarResult carResult)
        {
            lock (this)
            {
                if (Counter == 0)
                {
                    data[Counter++] = carResult;
                    return;
                }
                int position = Counter;
                for (int i = 0; i < Counter; i++)
                {
                    if (carResult.Car.Year < data[i].Car.Year)
                    {
                        position = i;
                        break;
                    }
                }

                for (int i = Counter; i >= position; i--)
                {
                    data[i + 1] = data[i];
                }
                data[position] = carResult;
                Counter++;
            }
        }