?? bubblesort.cpp
字號:
#include <iostream.h>
#include "datatype.h"
void BubbleSort(datatype a[], int n)
//用冒泡排序法對a[0]--a[n-1]排序
{
int i, j, flag=1;
datatype temp;
for(i = 1; i < n && flag == 1; i++)
{
flag = 0;
for(j = 0; j < n-i; j++)
{
if(a[j].key > a[j+1].key)
{
flag = 1;
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}
void main(void)
{
datatype test[6]={64,5,7,89,6,24};
int n = 6;
BubbleSort(test,n);
for(int i=0; i<n; i++)
cout << test[i].key << " ";
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -