i need p[i] to print in the text file and just entering output in void print isnt cutting it nor is calling the function in my output statement in main under radixsort..
any help at all is appreciated...thanks.
void print(int *p,int s)
{
int i;
for(i = 0; i < s; i++)
cout << p[i] << " ";
cout << endl;
}
void radixsort(int *p,int s)
{
int i, a[MAX], c = 0, first = 1;
for(i = 0; i < s; i++)
{
if(p[i] > c)
c = p[i];
}
while(c/first > 0)
{
int temp[10]={0};
for(i = 0; i < s; i++)
temp[p[i]/first%10]++;
for(i = 1 ; i < 10; i++)
temp[i]+=temp[i-1];
for(i = s-1; i >= 0; i--)
a[--temp[p[i]/first%10]]=p[i];
for(i = 0; i < s; i++)
p[i]=a[i];
first*=10;
cout << "\nSorted numbers: ";
print(p,s);
}
}
int main()
{
char textFile[20];
int arr[MAX];
int i, s;
cout << "Enter name of file to save sorted numbers to: ";
cin >> textFile;
ofstream output;
output.open(textFile);
output << textFile << endl;
cout << "Enter total numbers to be sorted (numbers must be less than " <<
MAX << "): ";
output << "Total numbers to be sorted: ";
cin >> s;
output << s << endl;
cout << "Enter " << s << " numbers: " << " ";
output << "Numbers to be sorted: ";
for(i = 0; i < s; i++)
{
cin >> arr[i];
output << arr[i] << " ";
}
radixsort(&arr[0], s);
//output << "\nSorted numbers: " ;
output.close();
system("PAUSE");
return 0;
}

New Topic/Question
Reply



MultiQuote




|