排序演算法(c 編寫)

2021-07-07 04:08:15 字數 1043 閱讀 5397

#include

using namespace std;

//選擇排序,計算出每個元素的名次

template

void rank1(t a, int n, int r)

}//原地重排

template

void rearrange(t a, int n, int r)

}//前n個元素中最大值的索引值

template

int indexofmax(t a,int n)

return maxindx;

}//選擇排序

template

void selectionrank(t a, int n)

}//selectionsort:及時終止的選擇排序

template

void selectionsort(t a,int n)

}//一次氣泡排序,如果一次氣泡排序中,沒有發生交換,則序列本身就是有序的,可終止排序

template

bool bubble(t a, int n)

}//氣泡排序

template

void bubblesort(t a, int n)

/*//一次氣泡排序,沒有及時終止排序

template

void bubble(t a, int n)

//氣泡排序

template

void bubblesort(t a, int n)

*///往有序數列a中插入數x,陣列大小為n

template

void insert1(t a, int n, const t& x)

//插入排序,陣列大小依次從1增到n

template

void insertionsort(t a, int n)

}int main()

;insertionsort(a,9);

for(int i = 0; i < 9; i++)

return 0;

}

java語言編寫的基本排序演算法

1 插入排序 1 直接插入排序 功能 直接插入排序演算法程式 複雜度為o n2 是穩定的排序演算法。基本思想 順序地把待排序的資料元素按其關鍵字值的大小插入到已排序的資料元素子集合的適當位置。packagecom.zyy.sorts public classdinsertsort 進行排序 int ...

C 排序演算法

最基本的 氣泡排序 c code using system namespace bubblesorter j public class mainclass bubblesorter sh new bubblesorter sh.sort iarrary for intm 0 m iarrary.le...

C 排序演算法

protected int bubbleup int array 氣泡排序 return array public int selectionsorter int list 選擇排序 int temp list min list min list i list i temp return list ...