Guest User

Untitled

a guest
May 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. st.Reset();
  2. st.Start();
  3. double temp;
  4. for (int pass = 1; pass < _arr.Length - 1; pass++)
  5. {
  6. // Count how many times this next loop
  7. // becomes shorter and shorter
  8. for (int i = 0; i < _arr.Length - pass; i++)
  9. {
  10. if (_arr[i] > _arr[i + 1])
  11. {
  12. // Exchange elements
  13. temp = _arr[i];
  14. _arr[i] = _arr[i + 1];
  15. _arr[i + 1] = temp;
  16. }
  17. }
  18. }
  19. st.Stop();
  20. Console.WriteLine("--Improvement 1--");
  21. Program.printArray(_arr);//Display the contents after each iteration of the algorithm
  22. Console.WriteLine("improvedBubbleSort 1 time taken to sort array: {0}", st.Elapsed);
Add Comment
Please, Sign In to add comment