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
|
Light Poster
|
|
| 23Dec2007,00:47 | #2 |
|
someone???
|
|
Go4Expert Founder
|
![]() |
| 23Dec2007,09:36 | #3 |
|
Quote:
Originally Posted by tzahi |
|
Light Poster
|
|
| 23Dec2007,11:46 | #4 |
|
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 ??? |
|
Go4Expert Founder
|
![]() |
| 23Dec2007,14:33 | #5 |
|
Yup
|
|
Light Poster
|
|
| 23Dec2007,19:15 | #6 |
|
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;
}
}
Last edited by shabbir; 23Dec2007 at 22:33.. Reason: Code block |
|
Light Poster
|
|
| 23Dec2007,23:18 | #7 |
|
Please someone can help me i need to submit the program Until tomorrow !!!
|

