Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- public static void Main()
- {
- int[] num = new int[] {5, 9, 4, 12, 8};
- int t;
- Console.WriteLine("Original Array:");
- Console.WriteLine("");
- foreach(int n in num)
- {
- Console.Write(n + " ");
- }
- Console.WriteLine("");
- Console.WriteLine("");
- for(int i = 0; i< num.Length - 1; i++)
- {
- for(int j = 0; j<num.Length - 1; j++)
- {
- if(num[j] > num[j+1])
- {
- t = num[j+1];
- num[j+1] = num[j];
- num[j] = t;
- }
- //Dispay steps inside of the bubble sort
- Console.WriteLine("Inside j loop: ");
- foreach(int n in num)
- {
- Console.Write(n + " ");
- }
- }
- }
- Console.WriteLine("Sorted Array: ");
- Console.WriteLine("");
- foreach(int n in num)
- {
- Console.Write(n + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment