I have this code which find longest nondecreasing sequence in array and print length of this sequence:
int max = 0;
void sequence(int *array, int start, int end, int last, int count)
{
int i;
if (start >= end)
{
if (count > max) max = count;
}
else
for (i = start; i < end; i++)
{
if (array[i] >= last)
sequence(array, i + 1, end, array[i], count + 1);
else
if (i == end - 1 && array[i] < last)
sequence(array, i + 1, end, 0, count);
}
}
void main()
{
int x[] = { 1, 2 };
sequence(x, 0, 2, 0, 0);
printf("%d", max);
}
Everything is OK in my Visual Studio, but Ideone print Runtime error time: 0 memory: 2160 signal:-1