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



Relevant Pages

  • (patch for Bash) regex case statement
    ... Following up on my previous patch for regex conditional tests, ... /* Return an array of strings; ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
    (comp.unix.shell)
  • Re: Strategy or Iterator?
    ... It would be possible to write a class that returns the variations ... GNU General Public License for more details. ... protected CombinatoricOperator(Telements, int r) { ... An integer array backing up the original one to keep track of the ...
    (comp.lang.java.programmer)
  • (patch for Bash) regex conditional tests
    ... 'regex' are returned in array variable SUBMATCH. ... Skipping of positional parameters, array elements, string ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
    (comp.unix.shell)
  • Re: The question regarding type of pointers
    ... int day_of_year ... According to my understanding daytab is pointing to the whole daytab ... array i.e it is equivalent to p3. ... daytab is converted to a pointer to the first ...
    (comp.lang.c)
  • Re: Warning on assigning a function-returning-a-pointer-to-arrays
    ... This declares pfunc as a function taking no arguments and returning ... int x, y; ... Presumably pfuncwill return a pointer to a single int, ... or the first of a sequence of "array 5 of int"s. ...
    (comp.lang.c)