请问这个插入排序的代码怎么写
这是我写的插入排序的代码,但是这个程序无法输出正常的结果,请问是怎么回事#include<iostream>
using namespace std;
int a = {2, 7, 1, 5, 8, 4, 6, 3}, n = 8;
void sort_a() {
for(int okpart=1; okpart<n; ++okpart) {
int i = okpart;
int temp = a;
while(i >= 1 && temp < a) {
a = a;
}
a = temp;
}
}
int main()
{
sort_a();
for(int i=0; i<n; ++i) {
cout<<a<<" ";
}
return 0;
} #include<iostream>
using namespace std;
int a = {2, 7, 1, 5, 8, 4, 6, 3}, n = 8;
void sort_a() {
for(int okpart=1; okpart<n; ++okpart) {
int i = okpart;
int temp = a;
while(i >= 1 && temp < a) {
a=a;
a=temp;
i--;
}
}
}
int main()
{
sort_a();
for(int i=0; i<n; ++i) {
cout<<a<<" ";
}
return 0;
}
页:
[1]