Search

함수2_개념04_정렬함수

대분류
STEP10 함수
소분류
함수2_개념

영상

개념

''' [정렬] [1] 오름차순 [23, 234, 1001, 3234, 32134] [2] 내림차순 [32134, 3234, 1001, 234, 23] ''' def myUpSort(a): for i in range(len(a)): j = i while j < len(a): if a[i] > a[j]: temp = a[i] a[i] = a[j] a[j] = temp j += 1 def myReverse(a): lastIndex = len(a) - 1 halfSize = int(len(a) / 2) for i in range(halfSize): temp = a[lastIndex] a[lastIndex] = a[i] a[i] = temp lastIndex-=1 a = [1001, 3234, 23, 32134, 234] print(a) myUpSort(a) print(a) myReverse(a) print(a)
Python
복사