void bubbleSort(int numbers[], int array_size){
int i, j, temp;
for (i = (array_size - 1); i >= 0; i--)
{ for (j = 1; j <= i; j++) { if (numbers[j-1] > numbers[j])
{
temp = numbers[j-1];
numbers[j-1] = numbers[j];
numbers[j] = temp;
}
}
}
}
# Quick Sort For String
///// U must declare ch[][] (for input) as global//////////////////////////
int string_sort(char *ch1,char *ch2)
{
int l1,l2;
l1=strlen(ch1);
l2=strlen(ch2);
if(l1==l2)
{
for(m=0;m
return 1;
else if(ch1[m]
return strcmp(ch1,ch2);
else if(l2>l1)
return strcmp(ch1,ch2);
return -1;
}
void quickSort(int array_size)
{
q_sort( 0, array_size - 1);
}
void q_sort( int left, int right)
{
int t,l_hold, r_hold;
char *pivot;
l_hold = left;
r_hold = right;
strcpy(pivot,ch[left]);
while (left <>
{
while (string_sort(ch[right],pivot)>0 && (left <>
right--;
if (left != right)
{ strcpy(ch[left],ch[right]); left++; }
while (string_sort(ch[left],pivot)<0>
left++;
if (left != right) { strcpy(ch[right],ch[left]); right--; }
}
strcpy(ch[left],pivot);
t = left;
left = l_hold;
right = r_hold;
if (left <>
q_sort(left, t-1);
if (right > t)
q_sort(t+1, right);
}
No comments:
Post a Comment