Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 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.Diagnostics;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using System.Reflection;
  13.  
  14. namespace Sorting
  15. {
  16. public partial class mainForm : Form
  17. {
  18. bool isRunning = true;
  19. List<int> intList = new List<int>();
  20. List<Pen> pens = new List<Pen>();
  21. bool sorted = false;
  22.  
  23. public mainForm()
  24. {
  25. InitializeComponent();
  26. this.Show();
  27. this.Focus();
  28. new Thread(() => initialize()).Start();
  29. new Thread(() => goSort()).Start();
  30. }
  31.  
  32. private void goSort()
  33. {
  34. for (int i = 0; i < 950; i++)
  35. {
  36. bool go = false;
  37. while (!go)
  38. {
  39. int randNum = new Random().Next(1, 1000);
  40. if (!intList.Contains(randNum))
  41. {
  42. go = true;
  43. }
  44. if (go)
  45. {
  46. intList.Add(randNum);
  47. }
  48. }
  49. }
  50.  
  51. for (int x = 0; x < 950; x++)
  52. {
  53. for (int y = 0; y < 950; y++)
  54. {
  55. if (y != 949)
  56. {
  57. if (intList[y] > intList[y + 1])
  58. {
  59. int temp0 = intList[y + 1];
  60. intList[y + 1] = intList[y];
  61. intList[y] = temp0;
  62. }
  63. }
  64. }
  65. }
  66.  
  67. sorted = true;
  68. }
  69.  
  70. private void initialize()
  71. {
  72. try
  73. {
  74. while (isRunning)
  75. {
  76. Invoke(new MethodInvoker(() =>
  77. {
  78. this.Invalidate();
  79. }));
  80. }
  81. }
  82. catch
  83. {
  84. }
  85. }
  86.  
  87. private void mainForm_Paint(object sender, PaintEventArgs e)
  88. {
  89. try
  90. {
  91. Graphics g = e.Graphics;
  92. for (int i = 0; i < intList.Count; i++)
  93. {
  94. g.DrawLine(Pens.ForestGreen, new Point(i, this.Size.Height), new Point(i, (int)Math.Floor(intList[i] / 2D)));
  95. drawMeme(i, g);
  96. }
  97. }
  98. catch (Exception ex)
  99. {
  100. }
  101. }
  102.  
  103. private void drawMeme(int val, Graphics g)
  104. {
  105. 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));
  106. if (!sorted)
  107. {
  108. g.DrawString("LINE " + val + " VALUE " + intList[val], new Font(this.Font.FontFamily, 24F, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Red, new PointF(10, 10));
  109. }
  110. else
  111. {
  112. g.DrawString("SORTED", new Font(this.Font.FontFamily, 24F, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Red, new PointF(10, 10));
  113. }
  114. }
  115.  
  116. private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
  117. {
  118. isRunning = false;
  119. System.Environment.Exit(0);
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement