疑难解答
#include <iostream>
using namespace std;
class Sort
{
public:
Swap(char x[],char y[]);
InsertionSort(int a[],int n,Sort &temp);
SelectionSort(char b[],char m);
private:
int X;char x[20],y[20],z[20];
int a[20];
char b[20];
};
Sort::InsertionSort(int a[],int n,Sort &temp)
{
X=temp.a[20];
int i,j;
for(i=1;i<n;i++)
{
i=j;
X=a[i];
while(j>0 &&X<a[j-1])
{
a[j]=a[j-1];
j--;
}
a[j]=X;
}
}
Sort::Swap(char x[],char y[])
{
char z[20];
x[20]=z[19];
x[20]=y[20];
y[20]=z[19];
}
Sort::SelectionSort(char b[],char m)
{
char smallindex;
char c,d;
for(c=0;c<m-1;c++)
{
smallindex=c;
for(d=c+1;d<m;d++)
if(b[d]<b[smallindex])
smallindex=d;
Swap(&b[c],&b[smallindex]);
}
}
void main()
{
char c;int i;
int a[20]={0};
cout<<"Enter the a[20]:";
for(i=0;i<20;i++)
cin>>a[i];
for(i=0;i<20;i++)
cout<<a[i]<<" "<<endl;
char b[20]={0};
cout<<"Enter the b[20]:";
for(c=0;c<20;c++)
cin>>b[c];
for(c=0;c<20;c++)
cout<<b[c]<<" "<<endl;
}
以上程序没有错误!程序运行的时候不能调用所写的排序算法!!希望各位帮帮忙~~把主函数改改使其能够调用所写的排序算法!!