Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //program.cs
- using System;
- using System.Windows.Forms;
- namespace sort
- {
- class Program
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("Podaj ilość elementów do posortowania:");
- int ilosc=int.Parse(Console.ReadLine());
- int[] tab=new int[ilosc];
- Console.WriteLine("Podaj dolną granicę przedziału:");
- int dol=int.Parse(Console.ReadLine());
- Console.WriteLine("Podaj górną granicę przedziału:");
- int gora=int.Parse(Console.ReadLine());
- sortuj.tab(ilosc, dol, gora, tab);
- string tekst1=sortuj.tostr(ilosc, tab);
- tab=sortuj.Bubble(ilosc, tab);
- string tekst2=sortuj.tostr(ilosc, tab);
- Application.Run( new Form1(tekst1) );
- Application.Run( new Form1(tekst2) );
- }
- }
- }
- //form.cs
- using System;
- using System.Windows.Forms;
- namespace sort
- {
- public partial class Form1 : Form
- {
- private Button ExitBtn;
- private Label etykieta;
- private void ExitWindow(object sender, EventArgs e)
- {
- Close();
- }
- public void EWBtn()
- {
- ExitBtn = new Button();
- ExitBtn.Parent = this;
- ExitBtn.AutoSize = true;
- //określam położenie przycisku zależnie od rozmiaru okna (na dole na środku)
- ExitBtn.Top = Height - ExitBtn.Height;
- ExitBtn.Left = 20+ Width/2 - ExitBtn.Width;
- ExitBtn.Text = "Zamknij Okno";
- //przechwycenie zdarzenia (kliknięcia przycisku) oraz wywołanie metody odpowiedzialnej za zamknięcie okna
- 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 = txt;
- }
- public Form1(string txt)
- {
- this.Text="Liczby";
- this.AutoSize = true;
- tekst(txt);
- EWBtn();
- }
- }
- }
- //sort.cs
- using System;
- namespace sort
- {
- 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[] tab1)
- {
- for(int i = 1; i < ilosc; ++i)
- {
- for(int j = ilosc - 1; j >= i; j--)
- if(tab1[j - 1] > tab1[j])
- {
- int x = tab1[j - 1];
- tab1[j - 1] = tab1[j];
- tab1[j] = x;
- }
- }
- return tab1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment