Facebook
From Lousy Gibbon, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 214
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication62
  8. {
  9.     class Program
  10.     {
  11.  
  12.         public static void test(int[] ar, int no){
  13.             int i, c, root, tmp;
  14.             for (i = 1; i <= no; i++){
  15.                 c = i;
  16.                 do{
  17.                     root=(c - 1) / 2;
  18.                     if (ar[root] < ar[c]){
  19.                         tmp = ar[root];
  20.                         ar[root] = ar[c];
  21.                         ar[c] = tmp;
  22.                     }
  23.                     c = root;
  24.                 } while(c!=0);
  25.             }
  26.         }
  27.  
  28.         public static void wypisz(int[] ar, int no){
  29.             int i;
  30.             for (i = 0; i <= no; i++){
  31.                 Console.WriteLine(ar[i]);
  32.  
  33.             }
  34.         }
  35.  
  36.         static void Main(string[] args)
  37.         {
  38.             int[] ar = { 5, 8, 7, 0, 1 };
  39.             int[] a = new int[5];
  40.             int i;
  41.             test(ar, 4);
  42.             wypisz(ar, 4);
  43.             for (i = 0; i <= 4; i++){
  44.                 test(ar, 4-i);
  45.                 a[i] = ar[0];
  46.                 ar[0] = ar[4 - i];
  47.             }
  48.             Console.WriteLine("===========================");
  49.             wypisz(a, 4);
  50.             Console.ReadLine();
  51.         }
  52.     }
  53. }
  54.