Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Need yuors help (http://www.go4expert.com/forums/need-yuors-help-t7974/)

tzahi 23Dec2007 00:09

Need yuors help
 
Hello.
I need to write a program in c that make merge Sort
the program will be writing in Recursion but i need to write in without loops

i wrot a program that make make merge in Recursion but with loops
and now i try to write it without loops and it doest work

if someone can write me the program i will thank him a lot !!!

bye,

here is a link how its need to work (but here is with loops )
http://en.wikipedia.org/wiki/Merge_sort

tzahi 23Dec2007 00:47

Re: Need yuors help
 
someone???

shabbir 23Dec2007 09:36

Re: Need yuors help
 
Quote:

Originally Posted by tzahi
someone???

Why don't you share your code so that we don't need to be doing it all over again.

tzahi 23Dec2007 11:46

Re: Need yuors help
 
I have only the code with loops
i delete the the code that i try to write without loops
Do you whnt me to share the code with the loops ???

shabbir 23Dec2007 14:33

Re: Need yuors help
 
Yup

tzahi 23Dec2007 19:15

Re: Need yuors help
 
this is my code if you can fix by take out the loops and it still do merge Sort :

Code:

void mergeSort(int numbers[], int temp[], int array_size)
{
  m_sort(numbers, temp, 0, array_size - 1);
}


void m_sort(int numbers[], int temp[], int left, int right)
{
  int mid;

  if (right > left)
  {
    mid = (right + left) / 2;
    m_sort(numbers, temp, left, mid);
    m_sort(numbers, temp, mid+1, right);

    merge(numbers, temp, left, mid+1, right);
  }
}

void merge(int numbers[], int temp[], int left, int mid, int right)
{
  int i, left_end, num_elements, tmp_pos;

  left_end = mid - 1;
  tmp_pos = left;
  num_elements = right - left + 1;

  while ((left <= left_end) && (mid <= right))
  {
    if (numbers[left] <= numbers[mid])
    {
      temp[tmp_pos] = numbers[left];
      tmp_pos = tmp_pos + 1;
      left = left +1;
    }
    else
    {
      temp[tmp_pos] = numbers[mid];
      tmp_pos = tmp_pos + 1;
      mid = mid + 1;
    }
  }

  while (left <= left_end)
  {
    temp[tmp_pos] = numbers[left];
    left = left + 1;
    tmp_pos = tmp_pos + 1;
  }
  while (mid <= right)
  {
    temp[tmp_pos] = numbers[mid];
    mid = mid + 1;
    tmp_pos = tmp_pos + 1;
  }

  for (i=0; i <= num_elements; i++)
  {
    numbers[right] = temp[right];
    right = right - 1;
  }
}


tzahi 23Dec2007 23:18

Re: Need yuors help
 
Please someone can help me i need to submit the program Until tomorrow !!!


All times are GMT +5.5. The time now is 06:53.