Skip to content

Instantly share code, notes, and snippets.

@kushalseth
Created August 9, 2020 19:34
Show Gist options
  • Save kushalseth/643c4ee6a2566ec251b780e9d81b728e to your computer and use it in GitHub Desktop.
Save kushalseth/643c4ee6a2566ec251b780e9d81b728e to your computer and use it in GitHub Desktop.
IsArraySorted
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