# Just a question

From: sj (kpsj2002_at_yahoo.com)
Date: 11/06/04

```Date: 6 Nov 2004 07:39:24 -0800

```

Hi;
I am trying to find the position of the maximum element of and array using
divide-and-conquer method. Following is the code I am trying.

#include <stdio.h>
#define MAX 7

int msort(char list[], int n)
{
int i, half1, half2;
char arr1[MAX/2+1];
char arr2[MAX/2+1];
if(n ==1) return 0;
else if (n==2){
if(list[0]>list[1]) return 0;
else return 1;
}else

{
half1 = n / 2;
half2 = n - half1;

for(i = 0; i < half1; i++)
arr1[i] = list[i];

for(i = 0; i < half2; i++)
arr2[i] = list[half1 + i];

int x1 = msort(arr1, half1);

int x2 = msort(arr2, half2);

if( list[x1] > list[x2]) return x1;
else
return x2;
}
}

int main()
{
int i, n;
char array[MAX];
n = 7;

array[0] = 'A';
array[1] = 'B';
array[2] = 'C';
array[3] = 'D';
array[4] = 'E';
array[5] = 'F';
array[6] = 'X';

int x = msort(array, n);

printf("%d ", x );

printf("\n");
return 0;
}

what am i doing wrong here?
thanks for any help

sj