Skip to content

Instantly share code, notes, and snippets.

Selectsort(x, n)
int x[], n;
{
int i, index, j, large;
for (i = n-1; i > 0; i--){
large=x[0];//要有初始值下面才能做判斷
index=0;
for (j = 1; j <= i; j++){
If (x[j]>large){
large=x[j];
Selectsort(x, n)
int x[], n;
{
int i, index, j, small;
for (i = 0; i <n; i++){
small=x[i];//要有初始值下面才能做判斷
index=i;
for (j = i+1; j < n; j++){
if (x[j]<small){
small=x[j];
//首先建一個計數陣列長度為內容範圍最大值加1,即長度為10。
Int count[10]={0};
//計算元素出現次數存入計數陣列
for (int i =0; i<n; i++) {
count[iArray[i]]+=1;
}
//建立輸出陣列
Int output [n]={0};
//遍歷計數陣列做排序
Int index=0;
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
def count_reverse_sort(a):
max=0
for i in a:
if i>max:
max=i
count=[None]*(max+1)
output=[None]*len(a)
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
def count_sort(a):
max=0
for i in a:
if i>max:
max=i
count=[None]*(max+1)
output=[None]*len(a)
def count_inversion(a):
count=0
for i in range(len(a)):
for j in range(i+1,len(a)):
if a[i]>a[j]:
count+=1
return count
print(count_inversion([3, 1, 2, 4]))
#output:2
def merge_two_orderedlist(a, b):
i, j = 0, 0
merged_list = []
# 比較兩個列表並將元素合併到merged_list
while i < len(a) and j < len(b):
if a[i] < b[j]:
merged_list.append(a[i]) # 改為append
i += 1
else:
"file:_vimrc
"There are different file names on Windows or Linux. So we have to check the file name.
if has('win32')
let $MYLOCALVIMRC = $HOME . "/_link.vim"
else
let $MYLOCALVIMRC = $HOME . "/.link.vim"
endif
"Read our link file
if filereadable($MYLOCALVIMRC)
source $MYLOCALVIMRC