Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Trab01ED02
- {
- public partial class Form1 : Form
- {
- List<int> arr;
- int temp;
- int count = 0;
- public Form1()
- {
- InitializeComponent();
- arr = new List<int>();
- testeARR();
- }
- public void testeARR()
- {
- arr.Add(800);
- arr.Add(500);
- int ccc;
- ccc = 550;
- while (ccc != 0)
- {
- arr.Add(ccc);
- arr.Add(ccc / 10);
- arr.Add(ccc / 5);
- ccc = ccc - 50;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- count = 0;
- for (int write = 0; write < arr.Count; write++)
- {
- for (int sort = 0; sort < arr.Count - 1; sort++)
- {
- if (arr[sort] > arr[sort + 1])
- {
- temp = arr[sort + 1];
- arr[sort + 1] = arr[sort];
- arr[sort] = temp;
- }
- count++;
- }
- }
- String s;
- s = Convert.ToString(count);
- textBox1.AppendText(s);
- textBox3.AppendText("O(n^2)");
- }
- private void button2_Click(object sender, EventArgs e)
- {
- count = 0;
- int smallestIndex, index, minIndex, temp;
- for (index = 0; index < arr.Count - 1; index++)
- {
- smallestIndex = index;
- for (minIndex = index; minIndex < arr.Count; minIndex++)
- {
- if (arr[minIndex] < arr[smallestIndex])
- smallestIndex = minIndex;
- temp = arr[smallestIndex];
- arr[smallestIndex] = arr[index];
- arr[index] = temp;
- count++;
- }
- }
- String s;
- s = Convert.ToString(count);
- textBox1.AppendText(s);
- textBox3.AppendText("O(n^2)");
- }
- private void button3_Click(object sender, EventArgs e)
- {
- count = 0;
- for (int i = 0; i < arr.Count - 1; i++)
- {
- int j;
- var insertionValue = arr[i];
- for (j = i; j > 0; j--)
- {
- if (arr[j - 1] > insertionValue)
- {
- arr[j] = arr[j - 1];
- }
- count++;
- }
- arr[j] = insertionValue;
- }
- String s;
- s = Convert.ToString(count);
- textBox1.AppendText(s);
- textBox3.AppendText("O(n)");
- }
- private void button4_Click(object sender, EventArgs e)
- {
- }
- //public void quicksort
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement