Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Plik 1 - Program.cs
- using System;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- namespace ConsoleApplication3
- {
- class Program
- {
- static Form1 Okno;
- static int[] tab0, tab1, tab2, tab3, tab4;
- static void bubblesort()
- {
- Okno.Invoke(new Action(delegate()
- {
- Okno.TxtBx2();
- }));
- DateTime start = DateTime.Now;
- sortuj.Bubble(tab1);
- DateTime stop = DateTime.Now;
- TimeSpan czas = stop - start;
- string a = sortuj.tostr(tab1);
- Okno.Invoke(new Action(delegate()
- {
- Okno.s1.Text = a;
- Okno.czas(1, czas);
- Okno.Update();
- }));
- }
- static void selectionsort()
- {
- Okno.Invoke(new Action(delegate()
- {
- Okno.TxtBx3();
- }));
- DateTime start = DateTime.Now;
- sortuj.Selection(tab2);
- DateTime stop = DateTime.Now;
- TimeSpan czas = stop - start;
- string a = sortuj.tostr(tab2);
- Okno.Invoke(new Action(delegate()
- {
- Okno.s2.Text = a;
- Okno.czas(2, czas);
- Okno.Update();
- }));
- }
- static void insertionsort()
- {
- Okno.Invoke(new Action(delegate()
- {
- Okno.TxtBx4();
- }));
- DateTime start = DateTime.Now;
- sortuj.Insertion(tab3);
- DateTime stop = DateTime.Now;
- TimeSpan czas = stop - start;
- string a = sortuj.tostr(tab3);
- Okno.Invoke(new Action(delegate()
- {
- Okno.s3.Text = a;
- Okno.czas(3, czas);
- Okno.Update();
- }));
- }
- static void quicksort()
- {
- Okno.Invoke(new Action(delegate()
- {
- Okno.TxtBx5();
- }));
- DateTime start = DateTime.Now;
- sortuj.Quick(tab4, 0, tab4.Length - 1);
- DateTime stop = DateTime.Now;
- TimeSpan czas = stop - start;
- string a = sortuj.tostr(tab4);
- Okno.Invoke(new Action(delegate()
- {
- Okno.czas(4, czas);
- Okno.s4.Text = a;
- Okno.Update();
- }));
- }
- static void StworzOkno()
- {
- Application.Run(Okno);
- }
- static void Main()
- {
- Console.WriteLine("Wprowadź liczbę elementów do posortowania:");
- int r = int.Parse(Console.ReadLine());
- Console.WriteLine("Wprowadź dolną granicę:");
- int dol = int.Parse(Console.ReadLine());
- Console.WriteLine("Wprowadź górną granicę:");
- int gora = int.Parse(Console.ReadLine());
- int j=0;
- tab0 = new int[r];
- Console.WriteLine("Czekaj, trwa tworzenie tablicy losowych liczb");
- sortuj.tab(r, dol, gora, tab0);
- tab1 = new int[r];
- tab2 = new int[r];
- tab3 = new int[r];
- tab4 = new int[r];
- tab0.CopyTo(tab1, 0);
- tab0.CopyTo(tab2, 0);
- tab0.CopyTo(tab3, 0);
- tab0.CopyTo(tab4, 0);
- Okno = new Form1(sortuj.tostr(tab0));
- Thread[] ThreadTable = new Thread[5];
- ThreadTable[0] = new Thread(StworzOkno);
- ThreadTable[1] = new Thread(bubblesort);
- ThreadTable[2] = new Thread(insertionsort);
- ThreadTable[3] = new Thread(selectionsort);
- ThreadTable[4] = new Thread(quicksort);
- foreach (Thread i in ThreadTable)
- {
- i.Start();
- Console.WriteLine("Uruchamiam Wątek {0} - " + (j == 0 ? "Tworzę okno" : "Rozpoczynam sortowanie metodą nr {1}"), ++j, j - 1);
- }
- }
- }
- }
- // PLIK 2 - CLASS1.cs
- using System;
- namespace ConsoleApplication3
- {
- public class sortuj
- {
- public static void tab(int ilosc, int dol, int gora, int[] tab)
- {
- Random a = new Random();
- for (int i = 0; i < ilosc; i++)
- {
- int x = a.Next(dol, gora);
- tab[i] = x;
- }
- }
- public static string tostr(int[] tab1)
- {
- string str1 = "";
- for (int i = 1; i <= tab1.Length; i++)
- str1 += tab1[i - 1] + " ";
- return str1;
- }
- public static void Bubble(int[] tab)
- {
- for (int i = 1; i < tab.Length; ++i)
- {
- for (int j = tab.Length - 1; j >= i; j--)
- if (tab[j - 1] > tab[j])
- {
- int x = tab[j - 1];
- tab[j - 1] = tab[j];
- tab[j] = x;
- }
- }
- }
- public static void Selection(int[] tab)
- {
- for (int i = 0; i < tab.Length - 1; i++)
- {
- for (int j = i; j < tab.Length; j++)
- if (tab[j] < tab[i])
- {
- int a = tab[j];
- tab[j] = tab[i];
- tab[i] = a;
- }
- }
- }
- public static void Insertion(int[] tab)
- {
- for (int i = 1; i < tab.Length; i++)
- for (int j = i; j - 1 >= 0 && tab[j] < tab[j - 1]; j--)
- {
- int a = tab[j];
- tab[j] = tab[j - 1];
- tab[j - 1] = a;
- }
- }
- public static void Quick(int[] tab, int left, int right)
- {
- int i=left;
- int j=right;
- int k=(left+right)/2;
- int x=tab[k];
- do{
- while(tab[i]<x) i++;
- while(tab[j]>x) j--;
- if(i<=j)
- {
- int a=tab[j];
- tab[j]=tab[i];
- tab[i]=a;
- i++;
- j--;
- }
- }while(i<=j);
- if(left<j) Quick(tab,left,j);
- if(right>i) Quick(tab,i,right);
- }
- }
- }
- //PLIK 3 - Form1.cs
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace ConsoleApplication3
- {
- public partial class Form1 : Form
- {
- private Button ExitBtn;
- private Label[] e = new Label[5];
- public TextBox start, s1, s2, s3, s4;
- private void ExitWindow(object sender, EventArgs e)
- {
- Close();
- }
- public void EWBtn()
- {
- ExitBtn = new Button();
- ExitBtn.Parent = this;
- ExitBtn.AutoSize = true;
- ExitBtn.Top = 530;
- ExitBtn.Left = 20 + Width / 2 - ExitBtn.Width;
- ExitBtn.Text = "Zamknij Okno";
- ExitBtn.Click += new System.EventHandler(ExitWindow);
- }
- public void tekst(int n, string txt, int top, int left)
- {
- n -= 1;
- e[n] = new Label();
- e[n].Parent = this;
- e[n].AutoSize = true;
- e[n].Top = top;
- e[n].Left = left;
- e[n].Text = txt;
- }
- public void czas(int n, TimeSpan t)
- {
- tekst(n, Convert.ToDecimal(t.TotalMilliseconds)/1000 + " sekund", 490, 370-(n-1)*120);
- }
- public void TxtBx(string ss)
- {
- tekst(1, "Liczby przed sortowaniem:", 10, 10);
- start = new System.Windows.Forms.TextBox();
- start.Parent = this;
- start.Top = 30;
- start.Left = 10;
- start.Size = new Size(500, 130);
- start.AcceptsReturn = true;
- start.Multiline = true;
- start.Text = ss;
- start.ScrollBars = ScrollBars.Vertical;
- }
- public void TxtBx2()
- {
- tekst(2, "BubbleSort:", 170, 370);
- s1 = new System.Windows.Forms.TextBox();
- s1.Parent = this;
- s1.Top = 190;
- s1.Left = 370;
- s1.Size = new Size(120, 300);
- s1.AcceptsReturn = true;
- s1.Multiline = true;
- s1.ScrollBars = ScrollBars.Vertical;
- }
- public void TxtBx3()
- {
- tekst(3, "SelectionSort:", 170, 250);
- s2 = new System.Windows.Forms.TextBox();
- s2.Parent = this;
- s2.Top = 190;
- s2.Left = 250;
- s2.Size = new Size(120, 300);
- s2.AcceptsReturn = true;
- s2.Multiline = true;
- s2.ScrollBars = ScrollBars.Vertical;
- }
- public void TxtBx4()
- {
- tekst(4, "InsertionSort:", 170, 130);
- s3 = new System.Windows.Forms.TextBox();
- s3.Parent = this;
- s3.Top = 190;
- s3.Left = 130;
- s3.Size = new Size(120, 300);
- s3.AcceptsReturn = true;
- s3.Multiline = true;
- s3.ScrollBars = ScrollBars.Vertical;
- }
- public void TxtBx5()
- {
- tekst(5, "QuickSort:", 170, 10);
- s4 = new System.Windows.Forms.TextBox();
- s4.Parent = this;
- s4.Top = 190;
- s4.Left = 10;
- s4.Size = new Size(120, 300);
- s4.AcceptsReturn = true;
- s4.Multiline = true;
- s4.ScrollBars = ScrollBars.Vertical;
- }
- public Form1(string txt)
- {
- this.Text = "Sortowanie";
- this.AutoSize = true;
- TxtBx(txt);
- EWBtn();
- }
- }
- }
- //INSTRUKCJA
- //zapisać te trzy pliki
- //stworzyć nowe rozwiązanie czy tam solucje
- //aplikacje konsoli
- //potem
- //po lewej
- //w oknie projekty
- //na nazwie (pogrubionej) kliknąć prawym
- //i dodaj->istniejący element
- //dodać te 3 pliki
- //i dodać referencje
- //system.drawing
- //system.windows.forms
- //system.threading
Advertisement
Add Comment
Please, Sign In to add comment