Facebook
From Beefy Mousedeer, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 198
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Sortowanie
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         List<decimal> listaLiczb = new List<decimal>();
  16.  
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void button1_Click(object sender, EventArgs e)
  23.         {
  24.            
  25.             listaLiczb.Add(numericUpDown1.Value);
  26.             refresh();
  27.         }
  28.  
  29.        
  30.  
  31.         void refresh()
  32.         {
  33.             listBox1.Items.Clear();
  34.             foreach (decimal liczba in listaLiczb)
  35.                 listBox1.Items.Add(liczba);
  36.         }
  37.  
  38.         private void button2_Click(object sender, EventArgs e)
  39.         {
  40.      
  41.  
  42.             for (int i = 0; i < listaLiczb.Count - 1; i++)
  43.             {
  44.                 if(listaLiczb[i]>listaLiczb[i+1])
  45.                 {
  46.                     decimal d = listaLiczb[i];
  47.                     listaLiczb[i] = listaLiczb[i + 1];
  48.                     listaLiczb[i + 1] = d;
  49.                     i = 0;
  50.                  }
  51.             }
  52.             refresh();
  53.         }
  54.     }
  55. }