Помогите,нужно сделать так что бы это приложение считало кол-во сравнений и обменов.Заранее спасибо.
Help
Код:
using System;
using System.Drawing;
using System.Windows.Forms;
using Sorts;
class RandomRectangle : Form
{
public Sort s1;
TextBox t1;
Button b1, b2;
PictureBox p1;
Graphics grfx;
public static void Main()
{
Application.Run(new RandomRectangle());
}
public RandomRectangle()
{
Text = "Sort";
Size = new System.Drawing.Size(800, 600);
DoubleBuffered = true;
p1 = new PictureBox();
{
p1.Size = new Size(700, 500);
p1.Left = 50;
p1.Top = 50;
p1.BackColor = Color.White;
grfx = p1.CreateGraphics();
this.Controls.Add(p1); }
t1 = new TextBox();
{
t1.Left = 10;
t1.Top = 10; }
b1 = new Button();
{
b1.Text = "Го";
b1.Left = 0;
b1.Top = 0;
b1.Size = new Size(50, 20);
b1.Click += new System.EventHandler(b1_Click);
this.Controls.Add(b1); }
b2 = new Button();
{
b2.Text = "Го";
b2.Left = 50;
b2.Top = 0;
b2.Size = new Size(50, 20);
b2.Click += new System.EventHandler(b2_Click);
this.Controls.Add(b2); } }
private void b1_Click(object sender, EventArgs e)
{
int[] m = new int[] { 3, 2, 1};
s1 = new Sort(m);
s1.Paint(grfx); }
private void b2_Click(object sender, EventArgs e)
{
s1.Sortirovka(grfx); }}
Krugok
Код:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Krugoks
{
public class Krugok
{
public int x, y;
int r;
int value;
Color color;
public Krugok(int cx, int cy, int cr, int cvalue, Color ccolor)
{
x = cx;
y = cy;
r = cr;
value = cvalue;
color = ccolor;
}
public int Get()
{
return this.value;
}
public void Set(int a)
{
this.value = a;
}
public void Paint(Graphics grfx)
{
grfx.FillEllipse(new SolidBrush(color), x, y, r, r);
grfx.DrawString(Convert.ToString(value), new System.Drawing.Font(
"Arial", 15), new
System.Drawing.SolidBrush(System.Drawing.Color.Black), x + 15, y + 10);
}
public void Clear(Graphics grfx)
{
grfx.FillEllipse(new SolidBrush(Color.White), x, y, r, r);
}
public void Move(Graphics grfx, Krugok move_kr)
{
//двигаем вниз или вверх
for (int i = 0; i < 50; i++)
{
this.Clear(grfx);
move_kr.Clear(grfx);
this.y = this.y + 1;
move_kr.y = move_kr.y - 1;
this.Paint(grfx);
move_kr.Paint(grfx);
System.Threading.Thread.Sleep(3);
}
int distance = Math.Abs(this.x - move_kr.x);
for (int i = 0; i < distance; i++)
{
this.Clear(grfx);
move_kr.Clear(grfx);
this.x = this.x + 1;
move_kr.x = move_kr.x - 1;
this.Paint(grfx);
move_kr.Paint(grfx);
System.Threading.Thread.Sleep(3);
}
//двигаем вниз или вверх
for (int i = 0; i < 50; i++)
{
this.Clear(grfx);
move_kr.Clear(grfx);
this.y = this.y - 1;
move_kr.y = move_kr.y + 1;
this.Paint(grfx);
move_kr.Paint(grfx);
System.Threading.Thread.Sleep(3);}}}}
Sort
Код:
using System;
using System.Drawing;
using System.Windows.Forms;
using Krugoks;
namespace Sorts
{
public class Sort
{
public Krugok[] mass;
public Sort(int[] m1)
{
mass = new Krugok[m1.Length];
for (int i = 0; i < m1.Length; i++)
{
mass[i] = new Krugok(50 * (i + 1), 50, 50, m1[i], Color.Green);}}
public void Paint(Graphics grfx)
{
for (int i = 0; i < mass.Length; i++)
{
mass[i].Paint(grfx);
}
}
public void Clear(Graphics grfx)
{
for (int i = 0; i < mass.Length; i++)
{
mass[i].Clear(grfx); } }
// метод случайной перемешки массива
private void shuffle(Graphics grfx)
{
Random random = new Random();
for (int i = 0; i < mass.Length; i++)
{
int k = random.Next(0, mass.Length);
if (k != i)
{
//обмен местами mass[i] и mass[k] ГРАФИКА
int massix = mass[i].x;
int masskx = mass[k].x;
if (k > i)
{
mass[i].Move(grfx, mass[k]);}
---
не забывайте форматировать код!
Модератор
----