Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 KB | None | 0 0
  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 Trab01ED02
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.  
  16.         List<int> arr;
  17.         int temp;
  18.         int count = 0;
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.             arr = new List<int>();
  23.             testeARR();
  24.         }
  25.  
  26.         public void testeARR()
  27.         {
  28.             arr.Add(800);
  29.             arr.Add(500);
  30.             int ccc;
  31.             ccc = 550;
  32.             while (ccc != 0)
  33.             {
  34.                 arr.Add(ccc);
  35.                 arr.Add(ccc / 10);
  36.                 arr.Add(ccc / 5);
  37.  
  38.                 ccc = ccc - 50;
  39.             }
  40.                
  41.  
  42.         }
  43.  
  44.         private void button1_Click(object sender, EventArgs e)
  45.         {
  46.             count = 0;
  47.             for (int write = 0; write < arr.Count; write++)
  48.             {
  49.                 for (int sort = 0; sort < arr.Count - 1; sort++)
  50.                 {
  51.                     if (arr[sort] > arr[sort + 1])
  52.                     {
  53.                         temp = arr[sort + 1];
  54.                         arr[sort + 1] = arr[sort];
  55.                         arr[sort] = temp;
  56.                     }
  57.                     count++;
  58.                 }
  59.             }
  60.             String s;
  61.             s = Convert.ToString(count);
  62.             textBox1.AppendText(s);
  63.             textBox3.AppendText("O(n^2)");
  64.  
  65.         }
  66.  
  67.         private void button2_Click(object sender, EventArgs e)
  68.         {
  69.             count = 0;
  70.             int smallestIndex, index, minIndex, temp;
  71.             for (index = 0; index < arr.Count - 1; index++)
  72.             {
  73.                 smallestIndex = index;
  74.                 for (minIndex = index; minIndex < arr.Count; minIndex++)
  75.                 {
  76.                     if (arr[minIndex] < arr[smallestIndex])
  77.                         smallestIndex = minIndex;
  78.                     temp = arr[smallestIndex];
  79.                     arr[smallestIndex] = arr[index];
  80.                     arr[index] = temp;
  81.                     count++;
  82.                 }
  83.             }
  84.             String s;
  85.             s = Convert.ToString(count);
  86.             textBox1.AppendText(s);
  87.             textBox3.AppendText("O(n^2)");
  88.            
  89.         }
  90.  
  91.         private void button3_Click(object sender, EventArgs e)
  92.         {
  93.             count = 0;
  94.             for (int i = 0; i < arr.Count - 1; i++)
  95.             {
  96.                 int j;
  97.                 var insertionValue = arr[i];
  98.                 for (j = i; j > 0; j--)
  99.                 {
  100.                     if (arr[j - 1] > insertionValue)
  101.                     {
  102.                         arr[j] = arr[j - 1];
  103.                        
  104.                     }
  105.                     count++;
  106.                 }
  107.                 arr[j] = insertionValue;
  108.             }
  109.  
  110.             String s;
  111.             s = Convert.ToString(count);
  112.             textBox1.AppendText(s);
  113.             textBox3.AppendText("O(n)");
  114.         }
  115.  
  116.         private void button4_Click(object sender, EventArgs e)
  117.         {
  118.  
  119.         }
  120.  
  121.  
  122.         //public void quicksort
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement