标签:++ and 大小 port list() 位置 ble 原理 print
import random
#构造数据
data = list()
for i in range(10):
data.append(random.randint(0, 100))
#打印数据
def show(array, lens):
for k in range(lens):
print("%3d" % array[k], end='')
print()
print("原始数据: ", end='')
show(data, 10)
#排序算法
for m in range(10 - 1):
for n in range(10 - m - 1):
if data[n] > data[n + 1]:
data[n], data[n + 1] = data[n + 1], data[n]
print("第%d次冒泡: " % (m + 1), end='')
show(data, 10)
print("排序结果: ", end='')
show(data, 10)
int * Bubble_Sort(int array[], int len)
{
if (array == NULL)
{
return NULL;
}
int temp = 0;
for(int i = 0; i < len - 1; i++)
{
for(int j = 0; j < len - i - 1; j++)
{
if(array[j] < array[j + 1])
{
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
return array;
}
import random
data = list()
for i in range(20):
data.append(random.randint(0, 100))
def show_array(array, lens):
for m in range(lens):
print("%4d" % (array[m]), end='')
print()
print("原始数据: ", end='')
show_array(data, 20)
for k in range(20 - 1):
min_num = k
for n in range(k+1, 20):
if data[n] < data[min_num]:
min_num = n
if min_num != k:
data[k], data[min_num] = data[min_num], data[k]
print("第%2d次交换:" % (k+1), end='')
show_array(data, 20)
print("顺序数据: ", end='')
show_array(data, 20)
int * Select_sort(int array[], int lens)
{
if (array == NULL)
{
return NULL;
}
for(int i = 0; i < lens - 1; i++)
{
int min = i;
for(int j = i + 1; j < lens; j++)
{
if (array[j] < array[min])
{
min = j;
}
}
if (min != i)
{
int temp = array[i];
array[i] = array[min];
array[min] = temp;
}
}
return array;
}
标签:++ and 大小 port list() 位置 ble 原理 print
原文地址:https://www.cnblogs.com/Hijack-you/p/11914000.html