1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
void Merg(int A[], int s1, int e1, int s2, int e2)
{
int B[8];
int i=0;
while (A[s1] < A[s2])
B[i] = B[s1];
i++;
s1++;
if (s1 == e1)
{
B[i] = A[s2];
i++;
s2++;
}
while (A[s2] < A[s1])
B[i] = B[s2];
i++;
s2++;
if (s2 == e2)
{
B[i] = A[s1];
i++;
s1++;
}
}
void Split(int A[], int s, int e)
{
int mid = (s+e)/2;
if (s < e && mid != 0)
{
Split(A, s, mid);
Split(A, mid+1, e);
}
Merg(A, s, mid, mid+1, e);
}
int main()
{
int A[8] = {10,4,8,12,11,2,7,5};
Split(A, 0, 7);
return 0;
}
Edit/Delete Message
|