一、选择
# Write your code here :-)
def own(ls):
min = ls[0]
m = 0
for i in range(0, len(ls)):
if ls[i] < min:
min = ls[i]
m = i
return m
def two(ls):
lb = []
for i in range(0, len(ls)):
m = own(ls)
lb.append(ls.pop(m))
return lb
ls = [78, 56, 89, 1, 4, 2, 5, 67, 7, 3, 23, 7, 34, 2, 5, 6, 12, 45]
print('排序前:',ls)
print('排序后:',two(ls))
l = [12, 90, 26, 367, 36, 23, 76, 45, 1, 9, 2, 8, 35, 27, 234, 24, 19, 89, 90]
print('排序前:', l)
print('排序后:', two(l))
二、
import sys
# 定义类型sort_big,small->big
class sort_big(object):
# 定义self参数
def __init__(self, f):
self.f = f
# 定义sorts函数,完成排序
def sorts(self):
for i in range(0, len(self.f)):
for j in range(0, len(self.f)-i-1):
if self.f[j] > self.f[j+1]:
self.f[j], self.f[j+1] = self.f[j+1], self.f[j]
return f
# 定义类型sort_small,big->small
class sort_small(object):
# 定义self参数
def __init__(self, f):
self.f = f
# 定义sorts函数,完成排序
def sorts(self):
for i in range(0, len(self.f)):
for j in range(0, len(self.f) - i - 1):
if self.f[j] < self.f[j + 1]:
self.f[j], self.f[j + 1] = self.f[j + 1], self.f[j]
return f
f = [int(x) for x in input().split(" ")]
a = f
# 通过调用类函数来进行排序(small->big)
x = sort_big(f)
f = x.sorts()
for i in f:
print(i, end=" ")
print(end='\n') # 换行,方便看清晰
# 通过调用类函数来进行排序(small->big)
y = sort_small(f)
f = y.sorts()
for i in f:
print(i, end=" ")
print(end='\n') # 换行,方便看清晰
# sys.exit()# 停止程序,为防止运行一下程序
a.sort() # 把列表升序
# a = sorted(a) # 把列表升序
# print(a)
a.sort(reverse=True) # 把列表降序
# a = sorted(a, reverse=True) # 把列表降序
# print(a)