1 <html><head><title>orden.pas</title></head><body bgcolor="#FFFFFF" text="#000000"><pre>
2 <font color="#444444">(**************************************************)</font>
\r
3 <font color="#444444">(* *)</font>
\r
4 <font color="#444444">(* ALGORITMOS DE ORDENAMIENTO *)</font>
\r
5 <font color="#444444">(* ========== == ============ *)</font>
\r
6 <font color="#444444">(* *)</font>
\r
7 <font color="#444444">(**************************************************)</font>
\r
9 <strong>program</strong> <font color="#993333">Ordenamientos</font><font color="#4444FF">;</font>
\r
11 <strong>const</strong>
\r
12 <font color="#993333">MAX</font> <font color="#4444FF">=</font> <font color="#FF0000">15</font><font color="#4444FF">;</font>
\r
14 <strong>type</strong>
\r
15 <font color="#993333">Dato</font> <font color="#4444FF">=</font> <font color="#993333">Integer</font><font color="#4444FF">;</font>
\r
16 <font color="#993333">Vector</font> <font color="#4444FF">=</font> <strong>array</strong> <font color="#4444FF">[</font><font color="#FF0000">1..</font><font color="#993333">MAX</font><font color="#4444FF">]</font> <strong>of</strong> <font color="#993333">Dato</font><font color="#4444FF">;</font>
\r
19 <font color="#444444">(****************************************************
\r
23 ****************************************************)</font>
\r
25 <strong>procedure</strong> <font color="#993333">bubbleSort</font><font color="#4444FF">(</font><strong>var</strong> <font color="#993333">v</font><font color="#4444FF">:</font> <font color="#993333">Vector</font><font color="#4444FF">;</font> <font color="#444444">{ Vector a ordenar }</font>
\r
26 <font color="#993333">min</font>, <font color="#444444">{ Valor de donde se comienza a ordenar }</font>
\r
27 <font color="#993333">max</font><font color="#4444FF">:</font> <font color="#993333">Integer</font><font color="#4444FF">)</font><font color="#4444FF">;</font> <font color="#444444">{ Valor en donde se termina de ordenar }</font>
\r
29 <strong>var</strong>
\r
30 <font color="#993333">i</font>, <font color="#993333">j</font>, <font color="#993333">aux</font><font color="#4444FF">:</font> <font color="#993333">integer</font><font color="#4444FF">;</font>
\r
32 <strong>begin</strong>
\r
33 <strong>if</strong> <font color="#993333">min</font> <font color="#4444FF"><</font> <font color="#993333">max</font> <strong>then</strong>
\r
34 <strong>for</strong> <font color="#993333">i</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">max</font> <font color="#4444FF">-</font> <font color="#FF0000">1</font> <strong>downto</strong> <font color="#993333">min</font> <strong>do</strong>
\r
35 <strong>for</strong> <font color="#993333">j</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">min</font> <strong>to</strong> <font color="#993333">i</font> <strong>do</strong>
\r
36 <strong>if</strong> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">]</font> <font color="#4444FF">></font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font> <strong>then</strong> <strong>begin</strong>
\r
37 <font color="#993333">aux</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
38 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
39 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">aux</font><font color="#4444FF">;</font>
\r
40 <strong>end</strong><font color="#4444FF">;</font>
\r
41 <strong>end</strong><font color="#4444FF">;</font> <font color="#444444">{ bubbleSort }</font>
\r
43 <font color="#444444">(****************************************************
\r
45 * BUBBLE SORT MEJORADO.
\r
47 ****************************************************)</font>
\r
49 <strong>procedure</strong> <font color="#993333">bubbleSortMejor</font><font color="#4444FF">(</font><strong>var</strong> <font color="#993333">v</font><font color="#4444FF">:</font> <font color="#993333">Vector</font><font color="#4444FF">;</font> <font color="#444444">{ Vector a ordenar }</font>
\r
50 <font color="#993333">min</font>, <font color="#444444">{ Valor de donde se comienza a ordenar }</font>
\r
51 <font color="#993333">max</font><font color="#4444FF">:</font> <font color="#993333">Integer</font><font color="#4444FF">)</font><font color="#4444FF">;</font> <font color="#444444">{ Valor en donde se termina de ordenar }</font>
\r
53 <strong>var</strong>
\r
54 <font color="#993333">i</font>, <font color="#993333">j</font>, <font color="#993333">aux</font><font color="#4444FF">:</font> <font color="#993333">integer</font><font color="#4444FF">;</font>
\r
55 <font color="#993333">huboInt</font><font color="#4444FF">:</font> <font color="#993333">Boolean</font><font color="#4444FF">;</font>
\r
57 <strong>begin</strong>
\r
58 <font color="#993333">huboInt</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">false</font><font color="#4444FF">;</font>
\r
59 <font color="#993333">i</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">max</font> <font color="#4444FF">-</font> <font color="#FF0000">1</font><font color="#4444FF">;</font>
\r
60 <strong>if</strong> <font color="#993333">min</font> <font color="#4444FF"><</font> <font color="#993333">max</font> <strong>then</strong>
\r
61 <strong>repeat</strong>
\r
62 <strong>for</strong> <font color="#993333">j</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">min</font> <strong>to</strong> <font color="#993333">i</font> <strong>do</strong>
\r
63 <strong>if</strong> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">]</font> <font color="#4444FF">></font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font> <strong>then</strong> <strong>begin</strong>
\r
64 <font color="#993333">aux</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
65 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
66 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">aux</font><font color="#4444FF">;</font>
\r
67 <font color="#993333">huboInt</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">true</font><font color="#4444FF">;</font>
\r
68 <strong>end</strong><font color="#4444FF">;</font>
\r
69 <font color="#993333">i</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">i</font> <font color="#4444FF">-</font> <font color="#FF0000">1</font><font color="#4444FF">;</font>
\r
70 <strong>until</strong> <strong>not</strong> <font color="#993333">huboInt</font><font color="#4444FF">;</font>
\r
71 <strong>end</strong><font color="#4444FF">;</font> <font color="#444444">{ bubbleSortMejor }</font>
\r
73 <font color="#444444">(****************************************************
\r
75 * SHAKE SORT (o Bubble Sort Bidireccional).
\r
77 ****************************************************)</font>
\r
79 <strong>procedure</strong> <font color="#993333">shakeSort</font><font color="#4444FF">(</font><strong>var</strong> <font color="#993333">v</font><font color="#4444FF">:</font> <font color="#993333">Vector</font><font color="#4444FF">;</font> <font color="#444444">{ Vector a ordenar }</font>
\r
80 <font color="#993333">min</font>, <font color="#444444">{ Valor de donde se comienza a ordenar }</font>
\r
81 <font color="#993333">max</font><font color="#4444FF">:</font> <font color="#993333">Integer</font><font color="#4444FF">)</font><font color="#4444FF">;</font> <font color="#444444">{ Valor en donde se termina de ordenar }</font>
\r
83 <strong>var</strong>
\r
84 <font color="#993333">i</font>, <font color="#993333">fin</font>, <font color="#993333">ini</font>, <font color="#993333">aux</font>, <font color="#993333">tmp</font><font color="#4444FF">:</font> <font color="#993333">integer</font><font color="#4444FF">;</font>
\r
86 <strong>begin</strong>
\r
87 <font color="#993333">fin</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">max</font> <font color="#4444FF">-</font> <font color="#FF0000">1</font><font color="#4444FF">;</font>
\r
88 <font color="#993333">ini</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">min</font><font color="#4444FF">;</font>
\r
89 <strong>if</strong> <font color="#993333">min</font> <font color="#4444FF"><</font> <font color="#993333">max</font> <strong>then</strong>
\r
90 <strong>repeat</strong>
\r
91 <font color="#993333">tmp</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">ini</font><font color="#4444FF">;</font>
\r
92 <strong>for</strong> <font color="#993333">i</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">ini</font> <strong>to</strong> <font color="#993333">fin</font> <strong>do</strong>
\r
93 <strong>if</strong> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">]</font> <font color="#4444FF">></font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font> <strong>then</strong> <strong>begin</strong>
\r
94 <font color="#993333">aux</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
95 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
96 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">aux</font><font color="#4444FF">;</font>
\r
97 <font color="#993333">tmp</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">i</font><font color="#4444FF">;</font>
\r
98 <strong>end</strong><font color="#4444FF">;</font>
\r
99 <font color="#993333">fin</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">tmp</font><font color="#4444FF">;</font>
\r
100 <strong>for</strong> <font color="#993333">i</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">fin</font> <strong>downto</strong> <font color="#993333">ini</font> <strong>do</strong>
\r
101 <strong>if</strong> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">]</font> <font color="#4444FF">></font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font> <strong>then</strong> <strong>begin</strong>
\r
102 <font color="#993333">aux</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
103 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
104 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">aux</font><font color="#4444FF">;</font>
\r
105 <font color="#993333">tmp</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">i</font><font color="#4444FF">;</font>
\r
106 <strong>end</strong><font color="#4444FF">;</font>
\r
107 <font color="#993333">ini</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">tmp</font><font color="#4444FF">;</font>
\r
108 <strong>until</strong> <font color="#993333">ini</font> <font color="#4444FF">></font><font color="#4444FF">=</font> <font color="#993333">fin</font><font color="#4444FF">;</font>
\r
109 <strong>end</strong><font color="#4444FF">;</font> <font color="#444444">{ shakeSort }</font>
\r
111 <font color="#444444">(****************************************************
\r
115 ****************************************************)</font>
\r
117 <strong>procedure</strong> <font color="#993333">insertionSort</font><font color="#4444FF">(</font><strong>var</strong> <font color="#993333">v</font><font color="#4444FF">:</font> <font color="#993333">Vector</font><font color="#4444FF">;</font> <font color="#444444">{ Vector a ordenar }</font>
\r
118 <font color="#993333">min</font>, <font color="#444444">{ Valor de donde se comienza a ordenar }</font>
\r
119 <font color="#993333">max</font><font color="#4444FF">:</font> <font color="#993333">Integer</font><font color="#4444FF">)</font><font color="#4444FF">;</font> <font color="#444444">{ Valor en donde se termina de ordenar }</font>
\r
121 <strong>var</strong>
\r
122 <font color="#993333">i</font>, <font color="#993333">j</font><font color="#4444FF">:</font> <font color="#993333">integer</font><font color="#4444FF">;</font>
\r
123 <font color="#993333">tmp</font><font color="#4444FF">:</font> <font color="#993333">Dato</font><font color="#4444FF">;</font>
\r
124 <font color="#993333">huboInt</font><font color="#4444FF">:</font> <font color="#993333">Boolean</font><font color="#4444FF">;</font>
\r
126 <strong>begin</strong>
\r
127 <strong>if</strong> <font color="#993333">min</font> <font color="#4444FF"><</font> <font color="#993333">max</font> <strong>then</strong>
\r
128 <strong>for</strong> <font color="#993333">i</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">min</font> <font color="#4444FF">+</font> <font color="#FF0000">1</font> <strong>to</strong> <font color="#993333">max</font> <strong>do</strong> <strong>begin</strong>
\r
129 <font color="#993333">tmp</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
130 <font color="#993333">j</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">i</font> <font color="#4444FF">-</font> <font color="#FF0000">1</font><font color="#4444FF">;</font>
\r
131 <font color="#993333">huboInt</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">true</font><font color="#4444FF">;</font>
\r
132 <strong>while</strong> <font color="#4444FF">(</font><font color="#993333">j</font> <font color="#4444FF">></font><font color="#4444FF">=</font> <font color="#FF0000">1</font><font color="#4444FF">)</font> <strong>and</strong> <font color="#993333">huboInt</font> <strong>do</strong>
\r
133 <strong>if</strong> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">]</font> <font color="#4444FF">></font> <font color="#993333">tmp</font> <strong>then</strong> <strong>begin</strong>
\r
134 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
135 <font color="#993333">j</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">j</font> <font color="#4444FF">-</font> <font color="#FF0000">1</font><font color="#4444FF">;</font>
\r
136 <strong>end</strong> <strong>else</strong>
\r
137 <font color="#993333">huboInt</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">false</font><font color="#4444FF">;</font>
\r
138 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">+</font><font color="#FF0000">1</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">tmp</font><font color="#4444FF">;</font>
\r
139 <strong>end</strong><font color="#4444FF">;</font>
\r
140 <strong>end</strong><font color="#4444FF">;</font> <font color="#444444">{ insertionSort }</font>
\r
142 <font color="#444444">(****************************************************
\r
146 ****************************************************)</font>
\r
148 <strong>procedure</strong> <font color="#993333">quickSort</font><font color="#4444FF">(</font><strong>var</strong> <font color="#993333">v</font><font color="#4444FF">:</font> <font color="#993333">Vector</font><font color="#4444FF">;</font> <font color="#444444">{ Vector a ordenar }</font>
\r
149 <font color="#993333">min</font>, <font color="#444444">{ Valor de donde se comienza a ordenar }</font>
\r
150 <font color="#993333">max</font><font color="#4444FF">:</font> <font color="#993333">Integer</font><font color="#4444FF">)</font><font color="#4444FF">;</font> <font color="#444444">{ Valor en donde se termina de ordenar }</font>
\r
152 <strong>var</strong>
\r
153 <font color="#993333">ini</font>, <font color="#993333">fin</font>, <font color="#993333">medio</font><font color="#4444FF">:</font> <font color="#993333">integer</font><font color="#4444FF">;</font>
\r
154 <font color="#993333">aux</font>, <font color="#993333">tmp</font><font color="#4444FF">:</font> <font color="#993333">Dato</font><font color="#4444FF">;</font>
\r
156 <strong>begin</strong>
\r
157 <strong>if</strong> <font color="#993333">min</font> <font color="#4444FF">></font><font color="#4444FF">=</font> <font color="#993333">max</font> <strong>then</strong>
\r
158 <font color="#993333">exit</font><font color="#4444FF">;</font>
\r
159 <font color="#993333">ini</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">min</font><font color="#4444FF">;</font>
\r
160 <font color="#993333">fin</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">max</font><font color="#4444FF">;</font>
\r
161 <font color="#993333">medio</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#4444FF">(</font><font color="#993333">min</font> <font color="#4444FF">+</font> <font color="#993333">max</font><font color="#4444FF">)</font> <strong>div</strong> <font color="#FF0000">2</font><font color="#4444FF">;</font>
\r
162 <font color="#993333">tmp</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">medio</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
163 <strong>repeat</strong>
\r
164 <strong>while</strong> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">ini</font><font color="#4444FF">]</font> <font color="#4444FF"><</font> <font color="#993333">tmp</font> <strong>do</strong>
\r
165 <font color="#993333">ini</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">ini</font> <font color="#4444FF">+</font> <font color="#FF0000">1</font><font color="#4444FF">;</font>
\r
166 <strong>while</strong> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">fin</font><font color="#4444FF">]</font> <font color="#4444FF">></font> <font color="#993333">tmp</font> <strong>do</strong>
\r
167 <font color="#993333">fin</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">fin</font> <font color="#4444FF">-</font> <font color="#FF0000">1</font><font color="#4444FF">;</font>
\r
168 <strong>if</strong> <font color="#993333">ini</font> <font color="#4444FF"><</font><font color="#4444FF">=</font> <font color="#993333">fin</font> <strong>then</strong> <strong>begin</strong>
\r
169 <strong>if</strong> <font color="#993333">ini</font> <font color="#4444FF"><</font> <font color="#993333">fin</font> <strong>then</strong> <strong>begin</strong>
\r
170 <font color="#993333">aux</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">ini</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
171 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">ini</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">fin</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
172 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">fin</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">aux</font><font color="#4444FF">;</font>
\r
173 <strong>end</strong><font color="#4444FF">;</font>
\r
174 <font color="#993333">ini</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">ini</font> <font color="#4444FF">+</font> <font color="#FF0000">1</font><font color="#4444FF">;</font>
\r
175 <font color="#993333">fin</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">fin</font> <font color="#4444FF">-</font> <font color="#FF0000">1</font><font color="#4444FF">;</font>
\r
176 <strong>end</strong><font color="#4444FF">;</font>
\r
177 <strong>until</strong> <font color="#993333">ini</font> <font color="#4444FF">></font> <font color="#993333">fin</font><font color="#4444FF">;</font>
\r
178 <strong>if</strong> <font color="#993333">min</font> <font color="#4444FF"><</font> <font color="#993333">fin</font> <strong>then</strong>
\r
179 <font color="#993333">quickSort</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#993333">min</font>, <font color="#993333">fin</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
180 <strong>if</strong> <font color="#993333">max</font> <font color="#4444FF">></font> <font color="#993333">ini</font> <strong>then</strong>
\r
181 <font color="#993333">quickSort</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#993333">ini</font>, <font color="#993333">max</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
182 <strong>end</strong><font color="#4444FF">;</font> <font color="#444444">{ quickSort }</font>
\r
184 <font color="#444444">(****************************************************
\r
188 ****************************************************)</font>
\r
190 <strong>procedure</strong> <font color="#993333">Shellsort</font><font color="#4444FF">(</font> <strong>var</strong> <font color="#993333">v</font> <font color="#4444FF">:</font> <font color="#993333">Vector</font><font color="#4444FF">;</font> <font color="#444444">{ Vector a ordenar }</font>
\r
191 <font color="#993333">min</font>, <font color="#444444">{ Valor de donde se comienza a ordenar }</font>
\r
192 <font color="#993333">max</font> <font color="#4444FF">:</font> <font color="#993333">Integer</font> <font color="#4444FF">)</font><font color="#4444FF">;</font> <font color="#444444">{ Valor en donde se termina de ordenar }</font>
\r
194 <strong>var</strong>
\r
195 <font color="#993333">i</font>, <font color="#993333">j</font>, <font color="#993333">medio</font> <font color="#4444FF">:</font> <font color="#993333">Integer</font><font color="#4444FF">;</font>
\r
196 <font color="#993333">tmp</font> <font color="#4444FF">:</font> <font color="#993333">Dato</font><font color="#4444FF">;</font>
\r
198 <strong>begin</strong>
\r
199 <font color="#993333">medio</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">max</font> <font color="#4444FF">-</font> <font color="#993333">min</font> <font color="#4444FF">+</font> <font color="#FF0000">1</font><font color="#4444FF">;</font>
\r
200 <strong>while</strong> <font color="#993333">medio</font> <font color="#4444FF">></font> <font color="#FF0000">1</font> <strong>do</strong> <strong>begin</strong>
\r
201 <strong>if</strong> <font color="#993333">medio</font> <font color="#4444FF"><</font> <font color="#FF0000">5</font> <strong>then</strong>
\r
202 <font color="#993333">medio</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#FF0000">1</font>
\r
203 <strong>else</strong>
\r
204 <font color="#993333">medio</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">trunc</font><font color="#4444FF">(</font> <font color="#FF0000">0.45454</font> <font color="#4444FF">*</font> <font color="#993333">medio</font> <font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
205 <font color="#444444">{*** Do linear insertion sort in steps size d ***}</font>
\r
206 <strong>for</strong> <font color="#993333">i</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">max</font> <font color="#4444FF">-</font> <font color="#993333">medio</font> <strong>downto</strong> <font color="#993333">min</font> <strong>do</strong> <strong>begin</strong>
\r
207 <font color="#993333">tmp</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
208 <font color="#993333">j</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">i</font> <font color="#4444FF">+</font> <font color="#993333">medio</font><font color="#4444FF">;</font>
\r
209 <strong>while</strong> <font color="#993333">j</font> <font color="#4444FF"><</font><font color="#4444FF">=</font> <font color="#993333">max</font> <strong>do</strong>
\r
210 <strong>if</strong> <font color="#993333">tmp</font> <font color="#4444FF">></font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">]</font> <strong>then</strong> <strong>begin</strong>
\r
211 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">-</font><font color="#993333">medio</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">]</font><font color="#4444FF">;</font>
\r
212 <font color="#993333">j</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">j</font> <font color="#4444FF">+</font> <font color="#993333">medio</font>
\r
213 <strong>end</strong> <strong>else</strong>
\r
214 <font color="#993333">break</font><font color="#4444FF">;</font>
\r
215 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">j</font><font color="#4444FF">-</font><font color="#993333">medio</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">tmp</font>
\r
216 <strong>end</strong><font color="#4444FF">;</font>
\r
217 <strong>end</strong><font color="#4444FF">;</font>
\r
218 <strong>end</strong><font color="#4444FF">;</font> <font color="#444444">{ Shellsort }</font>
\r
221 <font color="#444444">(************************************************************************)</font>
\r
223 <strong>procedure</strong> <font color="#993333">verVector</font><font color="#4444FF">(</font><strong>var</strong> <font color="#993333">v</font><font color="#4444FF">:</font> <font color="#993333">Vector</font><font color="#4444FF">;</font> <font color="#993333">s</font><font color="#4444FF">:</font> <font color="#993333">String</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
225 <strong>var</strong>
\r
226 <font color="#993333">i</font><font color="#4444FF">:</font> <font color="#993333">Integer</font><font color="#4444FF">;</font>
\r
228 <strong>begin</strong>
\r
229 <font color="#444444">(** MUESTRA VECTOR **)</font>
\r
230 <font color="#993333">writeln</font><font color="#4444FF">(</font><font color="#993333">s</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
231 <strong>for</strong> <font color="#993333">i</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#FF0000">1</font> <strong>to</strong> <font color="#993333">MAX</font> <strong>do</strong>
\r
232 <font color="#993333">write</font><font color="#4444FF">(</font><font color="#008000">' | '</font>, <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">]</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
233 <font color="#993333">writeln</font><font color="#4444FF">(</font><font color="#008000">' | '</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
234 <font color="#993333">writeln</font><font color="#4444FF">;</font>
\r
235 <strong>end</strong><font color="#4444FF">;</font> <font color="#444444">{ verVector }</font>
\r
238 <font color="#444444">(************************************************************************)</font>
\r
240 <strong>procedure</strong> <font color="#993333">cargarVector</font><font color="#4444FF">(</font><strong>var</strong> <font color="#993333">v</font><font color="#4444FF">:</font> <font color="#993333">Vector</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
242 <strong>var</strong>
\r
243 <font color="#993333">i</font><font color="#4444FF">:</font> <font color="#993333">Integer</font><font color="#4444FF">;</font>
\r
245 <strong>begin</strong>
\r
246 <font color="#444444">(** INICIALIZA VECTOR **)</font>
\r
247 <strong>for</strong> <font color="#993333">i</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#FF0000">1</font> <strong>to</strong> <font color="#993333">MAX</font> <strong>do</strong>
\r
248 <font color="#993333">v</font><font color="#4444FF">[</font><font color="#993333">i</font><font color="#4444FF">]</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">round</font><font color="#4444FF">(</font><font color="#993333">random</font> <font color="#4444FF">*</font> <font color="#FF0000">100</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
249 <strong>end</strong><font color="#4444FF">;</font> <font color="#444444">{ cargarVector }</font>
\r
252 <font color="#444444">(************************************************************************)</font>
\r
253 <font color="#444444">(************************************************************************)</font>
\r
254 <font color="#444444">(* PROGRAMA PRINCIPAL *)</font>
\r
256 <strong>var</strong>
\r
257 <font color="#993333">i</font><font color="#4444FF">:</font> <font color="#993333">Integer</font><font color="#4444FF">;</font>
\r
258 <font color="#993333">v</font>, <font color="#993333">w</font><font color="#4444FF">:</font> <font color="#993333">Vector</font><font color="#4444FF">;</font>
\r
260 <strong>begin</strong>
\r
261 <font color="#993333">cargarVector</font><font color="#4444FF">(</font><font color="#993333">w</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
262 <font color="#993333">v</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">w</font><font color="#4444FF">;</font>
\r
263 <font color="#993333">verVector</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#008000">'Desordenado:'</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
264 <font color="#993333">bubbleSort</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#FF0000">1</font>, <font color="#993333">MAX</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
265 <font color="#993333">verVector</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#008000">'Bubble Sort:'</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
266 <font color="#993333">bubbleSortMejor</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#FF0000">1</font>, <font color="#993333">MAX</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
267 <font color="#993333">verVector</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#008000">'Bubble Sort Mejorado:'</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
268 <font color="#993333">v</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">w</font><font color="#4444FF">;</font>
\r
269 <font color="#993333">shakeSort</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#FF0000">1</font>, <font color="#993333">MAX</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
270 <font color="#993333">verVector</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#008000">'Shake Sort (Bubble Sort Bidireccional):'</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
271 <font color="#993333">v</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">w</font><font color="#4444FF">;</font>
\r
272 <font color="#993333">insertionSort</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#FF0000">1</font>, <font color="#993333">MAX</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
273 <font color="#993333">verVector</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#008000">'Insertion Sort:'</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
274 <font color="#993333">v</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">w</font><font color="#4444FF">;</font>
\r
275 <font color="#993333">quickSort</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#FF0000">1</font>, <font color="#993333">MAX</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
276 <font color="#993333">verVector</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#008000">'Quick Sort:'</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
277 <font color="#993333">v</font> <font color="#4444FF">:</font><font color="#4444FF">=</font> <font color="#993333">w</font><font color="#4444FF">;</font>
\r
278 <font color="#993333">shellSort</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#FF0000">1</font>, <font color="#993333">MAX</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
279 <font color="#993333">verVector</font><font color="#4444FF">(</font><font color="#993333">v</font>, <font color="#008000">'Shell'</font><font color="#008000">'s Sort:'</font><font color="#4444FF">)</font><font color="#4444FF">;</font>
\r
280 <strong>end</strong>.
\r