Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace zad3
- {
- class Program
- {
- static void Main( string[] args )
- {
- char[] alfabet = { 'A', 'F', 'B', 'C', 'F', 'B', 'C' };
- AlfabetSort( alfabet );
- foreach( char a in alfabet )
- Console.Write( a );
- Console.ReadKey();
- }
- static void AlfabetSort( char[] tab )
- {
- int[] wystapienia = new int[ 6 ]; // Ilość Wystąpień znaków A, B, C, D, E F
- char[] w = new char[ tab.Length ];
- foreach( char a in tab )
- wystapienia[ a - 'A' ]++;
- for( int i = 1; i < wystapienia.Length; i++ )
- wystapienia[ i ] += wystapienia[ i - 1 ];
- for( int i = tab.Length-1; i >= 0 ; i-- )
- {
- int p = wystapienia[ tab[ i ] - 'A' ];
- w[ p - 1 ] = tab[ i ];
- wystapienia[ tab[ i ] - 'A' ]--;
- }
- Array.Copy( w, tab, tab.Length );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement