ПО Алгоритма сортировки для сортировки выбором и гномьей (неполная программа)

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication10
{
    /// <summary>
    /// Логика взаимодействия для MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public ObservableCollection<int> num1 = new ObservableCollection<int>();
        public ObservableCollection<int> num2 = new ObservableCollection<int>();
        List<int> dataX = new List<int>();
        List<int> dataY1 = new List<int>();
        List<int> dataY2 = new List<int>();
        DrawingGroup draw = new DrawingGroup();

        public MainWindow()
        {
            InitializeComponent();
            num1.CollectionChanged += Data_CollectionChanged;
            num2.CollectionChanged += Data_CollectionChanged;
            image.Source = new DrawingImage(draw);
            BackgroundFunc(minz, z, minq, q);
            FuncBild1(dataX, dataY1, q);

        }

        int minz = 0;
        int h = 1;
        const int countIntervals = 2;
        int z = 0;
        int q1 = 0;
        int q = 0;
        int minq = 0;

        void DataXFill(int minz, int h, int countIntervals, List<int> dataX)
        {
            for (int i = 0; i < countIntervals; i++)
            {
                dataX.Add(minz + i * h);
            }
        }

        void DataY1Fill(int minq, int h, int countIntervals, List<int> dataY1)
        {
            for (int i = 0; i < countIntervals; i++)
            {
                dataY1.Add(q + i * h);
            }
        }

        void DataY2Fill(int minq, int h, int countIntervals, List<int> dataY2)
        {
            for (int i = 0; i < countIntervals; i++)
            {
                dataY2.Add(q1 + i * h);
            }
        }



        private void button_Click(object sender, RoutedEventArgs e)
        {
            string vhod = "";
            string al = "";
            vhod = textBox.Text;
            vhod += " ";

        for (int i = 0; i < vhod.Length; i++)
            {
                if (vhod[i] == ' ')
                {
                    z++;
                }
            }


        for (int i = 0; i < vhod.Length - 1; i++)
            {

                if (vhod[i] != ' ')
                {
                    al += vhod[i];
                }
                else
                { 
                    al = "";
                }

                if ((al != "") && (vhod[i + 1] == ' '))
                {
                    num1.Add(Convert.ToInt32(al));
                }
            }

          for (int i = 0; i < vhod.Length - 1; i++)

            {
                if (vhod[i] != ' ')
                {
                    al += vhod[i];
                }
                else
                {
                    al = "";
                }
                if ((al != "") && (vhod[i + 1] == ' '))
                {
                    num2.Add(Convert.ToInt32(al));
                    num2[0] = num1[0];
                }
            }
            //MessageBox.Show(Convert.ToString(z));
            textBox.Clear();
        }

        private void button1_Click(object sender, RoutedEventArgs e)//заполнение случайными числами
        {
            if (textBox.Text != "")
            {
                Random rand = new Random();
                int temp;
                z = Convert.ToInt32(textBox.Text);
                for (int i = 0; i < Convert.ToInt32(textBox.Text); i++)
                {
                    temp = rand.Next(-100, 101);
                    num1.Add(temp);
                    num2.Add(temp);
                }
                textBox.Clear();
            }
            else
            {
                MessageBox.Show("Ошибка! Проверьте введенные данные");
            }
        }

        private void button2_Click(object sender, RoutedEventArgs e)//замена значений
        {
            int index = num1.IndexOf(Convert.ToInt32(textBox1.Text));
            num1.RemoveAt(index);
            num1.Insert(index, Convert.ToInt32(textBox2.Text));

            index = num2.IndexOf(Convert.ToInt32(textBox1.Text));
            num2.RemoveAt(index);
            num2.Insert(index, Convert.ToInt32(textBox2.Text));
        }

        private void button3_Click(object sender, RoutedEventArgs e)//очистка
        {
            num1.Clear();
            num2.Clear();
        }

        //графа работы с графиком
        private void BackgroundFunc(int minz, int z, int minq, int q)
        {
            GeometryDrawing geom = new GeometryDrawing();
            RectangleGeometry rect = new RectangleGeometry();
            rect.Rect = new Rect(minz, minq, z - minz, q - minq);
            geom.Geometry = rect;
            geom.Pen = new Pen(Brushes.Brown, 0.01);
            geom.Brush = Brushes.LightGray;
            draw.Children.Add(geom);
        }


        private void FuncBild1(List<int> dataX, List<int> dataY, int q)
        {
            GeometryGroup geom1 = new GeometryGroup();
            for (int i = 0; i < dataX.Count - 1; i++)
            {
                LineGeometry line = new LineGeometry(new Point(dataX[i], q - dataY[i]), new Point(dataX[i + 1], q - dataY[i + 1]));
                geom1.Children.Add(line);
            }
            GeometryDrawing geomd = new GeometryDrawing();
            geomd.Geometry = geom1;
            geomd.Pen = new Pen(Brushes.Blue, 0.01);
            draw.Children.Add(geomd);
        }



        void Data_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            listBox.ItemsSource = num1;
            listBox1.ItemsSource = num2;
        }

        //        public static List<int> Selection(List<int> list)//сортировка выбором
        //        {
        //            for (int i = 0; i < list.Count - 1; i++)
        //            {
        //                int min = i;
        //                for (int j = i + 1; j < list.Count; j++)
        //                {
        //                    if (list[j] < list[min])
        //                    {
        //                        min = j;
        //                    }
        //                }
        //                int dummy = list[i];
        //                list[i] = list[min];
        //                list[min] = dummy;
        //            }
        //            return list;
        //        }
        ////        gnomeSort(a[0..size - 1]) гномья сортировка
        //            i = 1
        //              j = 2
        //         while i<size
        //        {
        //           if a[i - 1] > a[i]
        //             i = j;
        //                j ++
        //           else
        //         swap a[i - 1] and a[i] и i - -
        //         if i = 0, то i = j и j ++
        //          }
    }
}


Теги:
using, System, Windows, Convert, dataX, ToInt32, countIntervals, private, textBox, index, object, CollectionChanged, sender, public, dataY1, geomd, ObservableCollection, Click, RoutedEventArgs, Clear, GeometryDrawing, else, geom1, Collections, Length, dataY, Brushes, Children, dataY2, Count, MainWindow, MessageBox, summary, string, LineGeometry
Добавлено: 30 Мая 2016 16:16:02 Добавил: Nata Chek Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...