## Featured Replies in this Discussion

- by NarueStart by checking if an array is sorted. Or in your teacher's terms "single sorted". :icon_rolleyes: Once you have the logic for determining if a sequence of values is in sorted order or not, you can apply a filter such that only even numbers are considered or only odd numbers are considered. Then run the algorithm twice: once for even numbers and once for odd numbers. Problem solved.
- by Narue

Start by checking if an array is sorted. Or in your teacher's terms "single sorted". :icon_rolleyes: Once you have the logic for determining if a sequence of values is in sorted order or not, you can apply a filter such that only even numbers are considered or only odd numbers are considered. Then run the algorithm twice: once for even numbers and once for odd numbers. Problem solved.

Since I don't what you've already tried or where you're stuck, and this looks like a homework problem, I'll describe how I would approach the question.

You need to keep track of two things at any given time, an even number and an odd number. Because you're only interested in whether or not the numbers are arranged in ascending order, you only need to compare each number (even or odd) to the corresponding number that preceded it.

So for each number in the array, you should check to see whether it's even or odd, and then compare it to the appropriate type of number which came before it. While each comparison matches the ascending pattern, you can continue to examine the array. If any comparison fails, then you will know that the array cannot be double sorted.

Start by checking if an array is sorted. Or in your teacher's terms "single sorted". :icon_rolleyes: Once you have the logic for determining if a sequence of values is in sorted order or not, you can apply a filter such that only even numbers are considered or only odd numbers are considered. Then run the algorithm twice: once for even numbers and once for odd numbers. Problem solved.

can you do it through coding.......after this....

```
int[] a={5,2,4,3,1};
int value=a.Length-1;
int temp;
for (int j = 0; j < value; j++)
{
for (int i = 0; i < value; i++)
{
if (a[i] > a[i + 1])
{
temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
}
for (int k = 0; k < a.Length; k++)
Console.WriteLine(a[k]);
```

this give normal sorting .....and the output for this is ....

output:

1 2 3 4 5

Thank you for your reply............

I tried to do this ......

```
namespace double_sorted_array
{
class Program
{
static void Main(string[] args)
{
int[] a = { 6, 12, 1, 24, 3, 5 };
Console.WriteLine(isDoubleSorted(a));
}
static bool isDoubleSorted(int[] a)
{
int i, j, k;
int[] b = new int[0];
int[] c = new int[0];
bool res = false;
for (i = 0,j=0,k=0; i < a.Length; i++)
{
if (a[i] % 2 == 0)
{
b[j] = a[i];
j++;
}
else
{
c[k] = a[i];
k++;
}
}
if (issortArray(b))
{
if (issortArray(c))
{
res = true;
}
else
res = false;
}
else
res = false;
return res;
}
static bool issortArray(int[] a)
{
bool res=false;
int value = a.Length - 1;
for (int j = 0; j < value; j++)
{
for (int i = 0; i < value; i++)
{
if (a[i] > a[i + 1])
{
res = false;
}
else
res = true;
}
}
return res;
}
}
}
```

but, I am getting an error...it says....."array out of bounds in line 13 and 26.....can anyone help me get this done...............

Thanks in advance............