Created
August 9, 2020 19:34
-
-
Save kushalseth/643c4ee6a2566ec251b780e9d81b728e to your computer and use it in GitHub Desktop.
IsArraySorted
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class MainClass { | |
public static void Main (string[] args) { | |
int[] theArray = { 1, 3, 5, 7 }; | |
Console.WriteLine (IsArraySorted(theArray)); | |
} | |
public static bool IsArraySorted(int[] array) | |
{ | |
bool isSorted = false; | |
for (int i = 1; i < array.Length; i++) | |
{ | |
if (!(array[i-1] < array[i])) | |
{ | |
isSorted = false; | |
break; | |
} | |
else | |
{ | |
isSorted = true; | |
} | |
} | |
if (array.Length == 0 || array.Length == 1) | |
isSorted = true; | |
return isSorted; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment