Hi i work in visual studio 2015 c# console applications .
I try to make bubble sort to array unsorted but i cannot do that
i search for internet about that i understand idea .
it is make comparison between small and largest then swap items to make in order array
but i cannot understand this code .
so that what outer loop represent and inner loop represent ?
red lines for outer loop and inner loop
-
-
-
- using System;
- class bubblesort
- {
- static void Main(string[] args)
- {
- int[] a = { 30, 20, 50, 40, 10 };
- int t;
- Console.WriteLine("The Array is : ");
- for (int i = 0; i < a.Length; i++)
- {
- Console.WriteLine(a[i]);
- }
- for (int j = 0; j <= a.Length - 2; j++) outer loop
- {
- for (int i = 0; i <= a.Length - 2; i++) inner loop
- {
- if (a[i] > a[i + 1])
- {
- t = a[i + 1];
- a[i + 1] = a[i];
- a[i] = t;
- }
- }
- }
- Console.WriteLine("The Sorted Array :");
- foreach (int aray in a)
- Console.Write(aray + " ");
- Console.ReadLine();
- }
- }