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.Diagnostics;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Reflection;
- namespace Sorting
- {
- public partial class mainForm : Form
- {
- bool isRunning = true;
- List<int> intList = new List<int>();
- List<Pen> pens = new List<Pen>();
- bool sorted = false;
- public mainForm()
- {
- InitializeComponent();
- this.Show();
- this.Focus();
- new Thread(() => initialize()).Start();
- new Thread(() => goSort()).Start();
- }
- private void goSort()
- {
- for (int i = 0; i < 950; i++)
- {
- bool go = false;
- while (!go)
- {
- int randNum = new Random().Next(1, 1000);
- if (!intList.Contains(randNum))
- {
- go = true;
- }
- if (go)
- {
- intList.Add(randNum);
- }
- }
- }
- for (int x = 0; x < 950; x++)
- {
- for (int y = 0; y < 950; y++)
- {
- if (y != 949)
- {
- if (intList[y] > intList[y + 1])
- {
- int temp0 = intList[y + 1];
- intList[y + 1] = intList[y];
- intList[y] = temp0;
- }
- }
- }
- }
- sorted = true;
- }
- private void initialize()
- {
- try
- {
- while (isRunning)
- {
- Invoke(new MethodInvoker(() =>
- {
- this.Invalidate();
- }));
- }
- }
- catch
- {
- }
- }
- private void mainForm_Paint(object sender, PaintEventArgs e)
- {
- try
- {
- Graphics g = e.Graphics;
- for (int i = 0; i < intList.Count; i++)
- {
- g.DrawLine(Pens.ForestGreen, new Point(i, this.Size.Height), new Point(i, (int)Math.Floor(intList[i] / 2D)));
- drawMeme(i, g);
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void drawMeme(int val, Graphics g)
- {
- g.FillRectangle(Brushes.Black, new Rectangle(10, 10, (int)g.MeasureString("LINE " + val + " VALUE " + intList[val], new Font(this.Font.FontFamily, 24F, FontStyle.Bold, GraphicsUnit.Pixel)).Width, (int)g.MeasureString("LINE " + val + " VALUE " + intList[val], new Font(this.Font.FontFamily, 24F, FontStyle.Bold, GraphicsUnit.Pixel)).Height));
- if (!sorted)
- {
- g.DrawString("LINE " + val + " VALUE " + intList[val], new Font(this.Font.FontFamily, 24F, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Red, new PointF(10, 10));
- }
- else
- {
- g.DrawString("SORTED", new Font(this.Font.FontFamily, 24F, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Red, new PointF(10, 10));
- }
- }
- private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- isRunning = false;
- System.Environment.Exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement