Check if the characters of a given string are in alphabetical order | C # implementation of above approach import Arrays class ; Function that checks whether the string is in alphabetical order or not ; length of the string ; create a character array of the length of the string ; assign the string to character array ; sort the character array ; check if the character array is equal to the string or not ; Driver Code ; check whether the string is in alphabetical order or not
using System ; public class GFG { static bool isAlphabaticOrder ( String s ) { int n = s . Length ; char [ ] c = new char [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { c [ i ] = s [ i ] ; } Array . Sort ( c ) ; for ( int i = 0 ; i < n ; i ++ ) if ( c [ i ] != s [ i ] ) return false ; return true ; } static public void Main ( ) { String s = " aabbbcc " ; if ( isAlphabaticOrder ( s ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }