Yamentou

Untitled

Sep 29th, 2020
743
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. public class Bubble_Sort
  3. {
  4.   public static void Main (string[]args)
  5.   {
  6.     int[] a = { 3, 0, 2, 5, -1, 4, 1 };
  7.     int t;
  8.     Console.WriteLine ("Original array :");
  9.     foreach (int aa in a) Console.Write (aa + " ");
  10.  
  11.     for (int p = 0; p <= a.Length - 2; p++)
  12.       {
  13.     for (int i = 0; i <= a.Length - 2; i++)
  14.       {
  15.         if (a[i] > a[i + 1])
  16.           {
  17.         t = a[i + 1];
  18.         a[i + 1] = a[i];
  19.         a[i] = t;
  20.           }
  21.       }
  22.       }
  23.  
  24.     Console.WriteLine ("\n" + "Sorted array :");
  25.  
  26.     foreach (int aa in a) Console.Write (aa + " ");
  27.  
  28.     Console.Write ("\n");
  29.  
  30.   }
  31. }
  32.  
RAW Paste Data