j4ggi

asd

Jan 19th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.77 KB | None | 0 0
  1. /*
  2.  * Created by SharpDevelop.
  3.  * User: student1
  4.  * Date: 2015-01-19
  5.  * Time: 12:32
  6.  *
  7.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8.  */
  9. using System;
  10. using System.Drawing;
  11. using System.Windows.Forms;
  12.  
  13. namespace soort
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         private Button ExitBtn;
  18.         private Label etykieta;
  19.         public TextBox start,s1,s2,s3,s4;
  20.    
  21.         private void ExitWindow(object sender, EventArgs e)
  22.            {
  23.             Close();
  24.            }
  25.            public void EWBtn()
  26.            {
  27.             ExitBtn = new Button();
  28.             ExitBtn.Parent = this;
  29.             ExitBtn.AutoSize = true;
  30.             ExitBtn.Top = Height - ExitBtn.Height;
  31.             ExitBtn.Left = 20+ Width/2 - ExitBtn.Width;
  32.             ExitBtn.Text = "Zamknij Okno";
  33.             ExitBtn.Click += new System.EventHandler(ExitWindow);    
  34.            }
  35.            
  36.            public void tekst(string txt)
  37.            {
  38.                etykieta = new Label();
  39.                etykieta.Parent = this;
  40.                etykieta.AutoSize = true;
  41.                etykieta.Top = 20;
  42.                etykieta.Left = 20;
  43.                etykieta.Text = "Przed sortowaniem:";
  44.            }
  45.            public void TxtBx(string ss)
  46.            {
  47.             start = new System.Windows.Forms.TextBox();
  48.             start.Parent=this;
  49.             start.Top=10;
  50.             start.Left=10;
  51.             start.Size=new Size(500, 70);
  52.             start.AcceptsReturn=true;
  53.             start.Multiline=true;
  54.             start.Text=ss;
  55.             start.ScrollBars=ScrollBars.Vertical;
  56.            }
  57.            
  58.             public void TxtBx2(string ss)
  59.             {
  60.             s1=new System.Windows.Forms.TextBox();
  61.             s1.Parent=this;
  62.             s1.Top=120;
  63.             s1.Left=10;
  64.             s1.Size=new Size(70, 300);
  65.             s1.AcceptsReturn=true;
  66.             s1.Multiline=true;
  67.             s1.Text=ss;
  68.             s1.ScrollBars=ScrollBars.Vertical;
  69.             }
  70.            
  71.             public void TxtBx3(string ss)
  72.             {
  73.             s2=new System.Windows.Forms.TextBox();
  74.             s2.Parent=this;
  75.             s2.Top=230;
  76.             s2.Left=100;
  77.             s2.Size=new Size(70, 300);
  78.             s2.AcceptsReturn=true;
  79.             s2.Multiline=true;
  80.             s2.Text=ss;
  81.             s2.ScrollBars=ScrollBars.Vertical;
  82.             }
  83.            
  84.             public void TxtBx4(string ss)
  85.             {
  86.             s3=new System.Windows.Forms.TextBox();
  87.             s3.Parent=this;
  88.             s3.Top=340;
  89.             s3.Left=10;
  90.             s3.Size=new Size(70, 300);
  91.             s3.AcceptsReturn=true;
  92.             s3.Multiline=true;
  93.             s3.Text=ss;
  94.             s3.ScrollBars=ScrollBars.Vertical;
  95.             }
  96.            
  97.             public void TxtBx5(string ss)
  98.             {
  99.             s4=new System.Windows.Forms.TextBox();
  100.             s4.Parent=this;
  101.             s4.Top=450;
  102.             s4.Left=10;
  103.             s4.Size=new Size(70, 300);
  104.             s4.AcceptsReturn=true;
  105.             s4.Multiline=true;
  106.             s4.Text=ss;
  107.             s4.ScrollBars=ScrollBars.Vertical;
  108.             }
  109.            
  110.  
  111.            public Form1(string txt)
  112.         {
  113.             string sd="";
  114.             this.Text="Liczby";
  115.             this.AutoSize = true;
  116.             TxtBx(txt);
  117.             TxtBx2(sd);
  118.             TxtBx3(sd);
  119.             TxtBx4(sd);
  120.             TxtBx5(sd);
  121.             EWBtn();
  122.         }
  123.     }
  124. }
  125.  
  126. using System;
  127. namespace soort
  128. {
  129.         public  class sortuj
  130.         {  
  131.                 public  static void tab(int ilosc, int dol, int gora, int[] tab)
  132.                 {
  133.                         Random a = new Random();
  134.                         for (int i=0; i<ilosc; i++)
  135.                         {
  136.                                 int x = a.Next(dol, gora);
  137.                                 tab[i]= x;
  138.                         }
  139.                 }
  140.                 public static string tostr(int ilosc, int[] tab1)
  141.                 {
  142.                         string str1="";
  143.                         for (int i=1; i<=ilosc; i++)
  144.                                 str1+=tab1[i-1] + (i%((int) Math.Sqrt(ilosc))!=0 ? " ":"\n");
  145.  
  146.                         return str1;
  147.                 }
  148.                 public static int Bubble(int ilosc, int[] tab)
  149.                 {
  150.                        DateTime start=DateTime.Now;
  151.                        for(int i = 1; i < ilosc; ++i)
  152.                        {
  153.                          for(int j = ilosc - 1; j >= i; j--)
  154.                                 if(tab[j - 1] > tab[j])
  155.                                 {
  156.                                   int x = tab[j - 1];
  157.                                   tab[j - 1] = tab[j];
  158.                                   tab[j] = x;
  159.                                 }
  160.                        }
  161.                        DateTime stop=DateTime.Now;
  162.                        TimeSpan czas=stop - start;
  163.                        return Convert.ToInt32(czas.TotalMilliseconds);
  164.                 }
  165.                 public static int SelectionSort(int[] tab, int rozmiar)
  166.                 {
  167.                     DateTime start=DateTime.Now;
  168.                     for(int i=0;i<rozmiar-1;i++)
  169.                     {
  170.                         for(int j=i;j<rozmiar;j++)
  171.                             if(tab[j]<tab[i])
  172.                             {
  173.                                 int a=tab[j];
  174.                                 tab[j]=tab[i];
  175.                                 tab[i]=a;
  176.                             }
  177.                     }
  178.                        DateTime stop=DateTime.Now;
  179.                        TimeSpan czas=stop - start;
  180.                        return Convert.ToInt32(czas.TotalMilliseconds);
  181.                 }
  182.                 public static int InsertionSort(int[] tab, int rozmiar)
  183.                 {
  184.                     DateTime start=DateTime.Now;
  185.                     for (int i = 1; i < rozmiar; i++)
  186.                         for(int j = i; j-1 >= 0 && tab[j]<tab[j-1]; j--)
  187.                         {
  188.                             int a=tab[j];
  189.                             tab[j]=tab[j-1];
  190.                             tab[j-1]=a;
  191.                         }
  192.                    
  193.                        DateTime stop=DateTime.Now;
  194.                        TimeSpan czas=stop - start;
  195.                        return Convert.ToInt32(czas.TotalMilliseconds);
  196.                 }
  197.                 public static void quicksort(int[] tab, int left, int right)
  198.                 {
  199.                     int i=left;
  200.                     int j=right;
  201.                     int k=(left+right)/2;
  202.                     int x=tab[k];
  203.                     do{
  204.                         while(tab[i]<x) i++;
  205.                         while(tab[j]>x) j--;
  206.                         if(i<=j)
  207.                         {    
  208.                             int a=tab[j];
  209.                             tab[j]=tab[i];
  210.                             tab[i]=a;
  211.                             i++;
  212.                             j--;
  213.                         }
  214.                     }while(i<=j);
  215.                     if(left<j) quicksort(tab,left,j);
  216.                     if(right>i) quicksort(tab,i,right);  
  217.                 }
  218.         }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment