• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jun 27th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. procedure BinaryInserts(var mas:TMyArr; const n:integer; out cmp1,trans1:integer);
2.
3. var
4.
5. i,j,m,l,r,x:integer;
6.
7. begin
8.
9. for i:=1 to n-1 do
10.
11. begin
12.
13. x:=mas[i];
14.
15. l:=1;
16.
17. r:=i;
18.
19. while l<r do
20.
21. begin
22.
23. m:=(l+r) div 2;
24.
25. cmp1:=cmp1+1;
26.
27. if mas[m]<x then l:=m+1
28.
29. else r:=m;
30.
31. end;
32.
33. for j:=i downto r+1 do
34.
35. begin
36.
37. mas[j]:=mas[j-1];
38.
39. trans1:=trans1+1;
40.
41. end;
42.
43. mas[r]:=x;
44.
45. trans1:=trans1+1;
46.
47. end;
48.
49. end;
50. procedure StraightSelection(var mas:TMyArr; const n:integer; out cmp1,trans1:integer);
51.
52. var
53.
54. min,i,j,x:integer;
55.
56. begin
57.
58. for i:=1 to n-1 do
59.
60. begin
61.
62. min:=i;
63.
64. x:=mas[min];
65.
66. for j:=i+1 to n do
67.
68. begin
69.
70. cmp1:=cmp1+1;
71.
72. if mas[j]<x then
73.
74. begin
75.
76. min:=j;
77.
78. x:=mas[min];
79.
80. trans1:=trans1+1;
81.
82. end;
83.
84. end;
85.
86. trans1:=trans1+1;
87.
88. mas[min]:=mas[i];
89.
90. mas[i]:=x;
91.
92. end;
93.
94. end;
95.
96.
97. procedure QuickSort(var mas:TMyArr; L,R:integer; out cmp1,trans1:integer);
98.
99. var
100.
101. i,j,x,tmp:integer;
102.
103. begin
104.
105. i:=L;
106.
107. j:=R;
108.
109. x:=mas[(L+R) div 2];
110.
111. repeat
112.
113. while mas[i]<x do
114.
115. begin
116.
117. i:=i+1;
118.
119. cmp1:=cmp1+1;
120.
121. end;
122.
123. while mas[j]>x do
124.
125. begin
126.
127. j:=j-1;
128.
129. cmp1:=cmp1+1;
130.
131. end;
132.
133. if i<=j then
134.
135. begin
136.
137. tmp:=mas[i];
138.
139. mas[i]:=mas[j];
140.
141. mas[j]:=tmp;
142.
143. i:=i+1;
144.
145. j:=j-1;
146.
147. trans1:=trans1+1;
148.
149. end;
150.
151. until i>j;
152.
153. if L<j then QuickSort(mas, L, j,cmp1,trans1);
154.
155. if i<R then QuickSort(mas, i, R,cmp1,trans1);
156. end;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top