Im having a problem with the decending part of this bubble sort. Array a[] is sorted into acending
Array b[] is sorted into decending
The output is good for acending, but all 0 for decending.
Heres my source!
Code:
//David Thurlby
//CIS 150
//Assignment#6-7
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#define SIZE 20
int getRand();
int sortA();
int sortD();
int printSorted();
int a[SIZE];
int b[SIZE];
int count,swap1,swap2,hold;
int main()
{
printf("Getting Random Numbers\n");
getRand(a[SIZE]);
for(count=0;count<SIZE;count++)
printf("%4d",a[count]);
b[count]=a[count];
sortA(a[SIZE]);
sortD(b[SIZE]);
printf("\n\n");
printf("Swaps for A= %d\n",swap1);
printf("Swaps for D= %d\n",swap2);
printf("Press Any Key To Continue");
getch();
system("cls");
printSorted();
return 0;
}
int getRand()//getting Random num
{
srand(time(NULL));
for(count=0;count<=SIZE;count++)
{
a[count]=rand()%100;
}
return 0;
}
int sortA()//sort Acending
{
for(swap1=1;swap1<=SIZE-1;swap1++)
{
for(count=0;count<=SIZE-2;count++)
{
if(a[count]>a[count+1])
{
hold=a[count];
a[count]=a[count+1];
a[count+1]=hold;
}
}
}
return 0;
}
int sortD()//sort Decending
{
for(swap2=1;swap2<=SIZE-1;swap2++)
{
for(count=0;count<=SIZE-2;count++)
{
if(b[count]<b[count+1])
{
hold=b[count];
b[count]=b[count+1];
b[count+1]=hold;
}
}
}
return 0;
}
int printSorted()
{
for(count=0;count<SIZE;count++)
printf("%d\n",a[count]);
getch();
system("cls");
for(count=0;count<SIZE;count++)
printf("%d\n",b[count]);
return 0;
}
thanks for any help you can give me!