Advertisement
Danielos168

Zadanie 3

Nov 21st, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace zad3
  8. {
  9.     class Program
  10.     {
  11.         static void Main( string[] args )
  12.         {
  13.             char[] alfabet = { 'A', 'F', 'B', 'C', 'F', 'B', 'C' };
  14.  
  15.             AlfabetSort( alfabet );
  16.  
  17.             foreach( char a in alfabet )
  18.                 Console.Write( a );
  19.  
  20.             Console.ReadKey();
  21.         }
  22.  
  23.         static void AlfabetSort( char[] tab )
  24.         {
  25.             int[] wystapienia = new int[ 6 ];   // Ilość Wystąpień znaków A, B, C, D, E F
  26.             char[] w = new char[ tab.Length ];
  27.  
  28.             foreach( char a in tab )
  29.                 wystapienia[ a - 'A' ]++;
  30.  
  31.             for( int i = 1; i < wystapienia.Length; i++ )
  32.                 wystapienia[ i ] += wystapienia[ i - 1 ];
  33.  
  34.             for( int i = tab.Length-1; i >= 0 ; i-- )
  35.             {
  36.                 int p = wystapienia[ tab[ i ] - 'A' ];
  37.                 w[ p - 1 ] = tab[ i ];
  38.                 wystapienia[ tab[ i ] - 'A' ]--;
  39.             }
  40.  
  41.             Array.Copy( w, tab, tab.Length );
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement