主题:帮忙看看这个冒泡算法有什么问题??谢谢啦
#include "stdafx.h"
#include<iostream>
int main()
{
int Last = 8;
int List[9] = {0, 21,32,43,24,44,12,23,7};
int i , j ,swap;
for(i = 1; i < Last; i++)
{
swap = 0;
for(j = Last; j > i; j--)
{
if(List[j-1] > List[j])
{
List[0] = List[j-1];
List[j-1] = List[j];
List[j] = List[0];
swap = 1;
std::cout << swap << std::endl;
}
if(!swap)
{
break;
}
}
}
for(int i =1;i < 9 ;i++)
std::cout << List[i] << std::endl;
}
#include<iostream>
int main()
{
int Last = 8;
int List[9] = {0, 21,32,43,24,44,12,23,7};
int i , j ,swap;
for(i = 1; i < Last; i++)
{
swap = 0;
for(j = Last; j > i; j--)
{
if(List[j-1] > List[j])
{
List[0] = List[j-1];
List[j-1] = List[j];
List[j] = List[0];
swap = 1;
std::cout << swap << std::endl;
}
if(!swap)
{
break;
}
}
}
for(int i =1;i < 9 ;i++)
std::cout << List[i] << std::endl;
}