Def swap (sn, left, right) :
[left] sn, sn [right]=sn [right], sn [left]
# to find quick sort benchmark elements using different take big
Def findpivot (sn, left, right) :
If sn [left] <=sn [left + 1] :
Swap (sn, left, left + 1)
# based on quick sort to find the first k divided into small elements
Def findk (sn, left, right, k) :
Findpivot (sn, left, right)
I=left
J=right
The base=sn [left]
Print (sn)
# move from right to left, encounter less than base, moving from left to right, meet is greater than the base exchange position
While I & lt; J:
While i<[j] j and sn & gt;=base:
J=j - 1
While i
If i
If I==j and sn [I]
# for the first time after the exchange, look at the relationship between the I and k - 1, if it is i> K - 1, the sort of before I
While I!=k - 1:
If I & gt; K - 1:
Findk (sn, left, I - 1, k)
# if i
Findk (sn, I + 1, right, k - I)
Print (sn/k - 1)
Return
Sn=,1,4,9,2,6,5,30,32,34 [3]
Findk (sn, 0, len (sn) - 1, 4)
Thank you ~ ~ ~
CodePudding user response:
You are no return value of function,CodePudding user response:
If you just want to sort, find the first k small elements, you can write
Def finds (nums, num) :
N=num
While num & gt; 0:
For I in range (len (nums) - 1) :
If nums [I] & gt; Nums [I + 1] :
Nums [I], nums=nums [I + 1], [I + 1] nums [I]
Num=1
-Return nums nums [n - 1)
Nums=(3, 1, 4, 9, 2, 6, 5, 30, 32, 34]
Print (finds (nums, 4))
CodePudding user response: