"tests are to indicate the existence of a bug rather than not exist"--edsger Dijkstra
Description
Sorts and outputs n integers using a pointer to a pointer. Requires that the sort be written as a single function. Integers and n are entered in the main function. Finally, the output is in the main function.
Input
N and N integers
Output
The sorted integer
Sample Input
5
4 3 2 1 5
Sample Output
1 2 3 4 5
HINT
The main function is given as follows, and the following main functions are not required for submission
/* C code * *
int main ()
{
void sort (int **,int);
int i,n,data[20],**p,*pstr[20];
scanf ("%d", &n);
for (i=0; i<n; i++)
pstr[i]=&data[i];
for (i=0; i<n; i++)
scanf ("%d", pstr[i]);
P=PSTR;
Sort (p,n);
for (i=0; i<n; i++)
printf ("%d", *pstr[i]);
return 0;
}
/* C + + code * *
int main ()
{
void sort (int **,int);
int i,n,data[20],**p,*pstr[20];
cin>>n;
for (i=0; i<n; i++)
pstr[i]=&data[i];
for (i=0; i<n; i++)
cin>>*pstr[i];
P=PSTR;
Sort (p,n);
for (i=0; i<n; i++)
cout<<*pstr[i]<< "";
return 0;
}
Source:
#include <iostream>
using namespace std;
void sort (int **p,int n) {
int m,f;
for (int i=0;i<n;i++) {
m=* (*p+i);
f=i;
for (int j=i+1;j<n;j++) {
if (m>* (*p+j)) {
m=* (*p+j);
F=j
}
}
* (*p+f) =* (*p+i);
* (*p+i) =m
}
}
int main ()
{
void sort (int **,int);
int i,n,data[20],**p,*pstr[20];
cin>>n;
For (i=0 i<n; i++)
pstr[i]=&data[i];
For (i=0 i<n; i++)
cin>>*pstr[i];
P=pstr;
Sort (p,n);
for (i=0; i<n; i++)
cout<<*pstr[i]<< "";
return 0;
}