单项选择题

Are based on the following Pascal code.
FOR i:=1 TO n -1 do
BEGIN
k:=i:
FOR j:=i+1 TO n DO
IF A[j]
THEN k:=j:
IF k<>i
THEN BEGIN
X:=A[k];
A[k]:=A[i];
A[i]:=x
END
END;
<---> Suppose elements in array A are already sorted ascending order of their values when the code begins to run, then execution time of the code will be()

A.O(log2n)
B.O(n)
C.O(nlog2n)
D.O(n2)