Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop.
- * User: student1
- * Date: 2015-01-19
- * Time: 12:32
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace soort
- {
- public partial class Form1 : Form
- {
- private Button ExitBtn;
- private Label etykieta;
- 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 = Height - ExitBtn.Height;
- ExitBtn.Left = 20+ Width/2 - ExitBtn.Width;
- ExitBtn.Text = "Zamknij Okno";
- ExitBtn.Click += new System.EventHandler(ExitWindow);
- }
- public void tekst(string txt)
- {
- etykieta = new Label();
- etykieta.Parent = this;
- etykieta.AutoSize = true;
- etykieta.Top = 20;
- etykieta.Left = 20;
- etykieta.Text = "Przed sortowaniem:";
- }
- public void TxtBx(string ss)
- {
- start = new System.Windows.Forms.TextBox();
- start.Parent=this;
- start.Top=10;
- start.Left=10;
- start.Size=new Size(500, 70);
- start.AcceptsReturn=true;
- start.Multiline=true;
- start.Text=ss;
- start.ScrollBars=ScrollBars.Vertical;
- }
- public void TxtBx2(string ss)
- {
- s1=new System.Windows.Forms.TextBox();
- s1.Parent=this;
- s1.Top=120;
- s1.Left=10;
- s1.Size=new Size(70, 300);
- s1.AcceptsReturn=true;
- s1.Multiline=true;
- s1.Text=ss;
- s1.ScrollBars=ScrollBars.Vertical;
- }
- public void TxtBx3(string ss)
- {
- s2=new System.Windows.Forms.TextBox();
- s2.Parent=this;
- s2.Top=230;
- s2.Left=100;
- s2.Size=new Size(70, 300);
- s2.AcceptsReturn=true;
- s2.Multiline=true;
- s2.Text=ss;
- s2.ScrollBars=ScrollBars.Vertical;
- }
- public void TxtBx4(string ss)
- {
- s3=new System.Windows.Forms.TextBox();
- s3.Parent=this;
- s3.Top=340;
- s3.Left=10;
- s3.Size=new Size(70, 300);
- s3.AcceptsReturn=true;
- s3.Multiline=true;
- s3.Text=ss;
- s3.ScrollBars=ScrollBars.Vertical;
- }
- public void TxtBx5(string ss)
- {
- s4=new System.Windows.Forms.TextBox();
- s4.Parent=this;
- s4.Top=450;
- s4.Left=10;
- s4.Size=new Size(70, 300);
- s4.AcceptsReturn=true;
- s4.Multiline=true;
- s4.Text=ss;
- s4.ScrollBars=ScrollBars.Vertical;
- }
- public Form1(string txt)
- {
- string sd="";
- this.Text="Liczby";
- this.AutoSize = true;
- TxtBx(txt);
- TxtBx2(sd);
- TxtBx3(sd);
- TxtBx4(sd);
- TxtBx5(sd);
- EWBtn();
- }
- }
- }
- using System;
- namespace soort
- {
- 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 ilosc, int[] tab1)
- {
- string str1="";
- for (int i=1; i<=ilosc; i++)
- str1+=tab1[i-1] + (i%((int) Math.Sqrt(ilosc))!=0 ? " ":"\n");
- return str1;
- }
- public static int Bubble(int ilosc, int[] tab)
- {
- DateTime start=DateTime.Now;
- for(int i = 1; i < ilosc; ++i)
- {
- for(int j = ilosc - 1; j >= i; j--)
- if(tab[j - 1] > tab[j])
- {
- int x = tab[j - 1];
- tab[j - 1] = tab[j];
- tab[j] = x;
- }
- }
- DateTime stop=DateTime.Now;
- TimeSpan czas=stop - start;
- return Convert.ToInt32(czas.TotalMilliseconds);
- }
- public static int SelectionSort(int[] tab, int rozmiar)
- {
- DateTime start=DateTime.Now;
- for(int i=0;i<rozmiar-1;i++)
- {
- for(int j=i;j<rozmiar;j++)
- if(tab[j]<tab[i])
- {
- int a=tab[j];
- tab[j]=tab[i];
- tab[i]=a;
- }
- }
- DateTime stop=DateTime.Now;
- TimeSpan czas=stop - start;
- return Convert.ToInt32(czas.TotalMilliseconds);
- }
- public static int InsertionSort(int[] tab, int rozmiar)
- {
- DateTime start=DateTime.Now;
- for (int i = 1; i < rozmiar; 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;
- }
- DateTime stop=DateTime.Now;
- TimeSpan czas=stop - start;
- return Convert.ToInt32(czas.TotalMilliseconds);
- }
- public static void quicksort(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) quicksort(tab,left,j);
- if(right>i) quicksort(tab,i,right);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment