<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=1100864</guid>
        <pubDate>Mon, 15 May 2006 08:08:08 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=1100864</link>
        <description><![CDATA[Swindler: <strong class='tag-b'>haa</strong>, обращайся, на то ж и форуи :). Только б ты новую тему завела, а то подняла какую-то доисторическую  :yes: .]]></description>
        <author>Swindler</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=1100856</guid>
        <pubDate>Mon, 15 May 2006 08:04:27 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=1100856</link>
        <description><![CDATA[haa: Можно к Вам обратиться за помощью?]]></description>
        <author>haa</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93741</guid>
        <pubDate>Mon, 09 Dec 2002 21:37:49 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93741</link>
        <description><![CDATA[alexgrus: <div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <span class='tag-quote__quote-info'>new, 09.12.02, 11:48:42</span><div class='quote '>1</div></div><br><br>Очень остроумно. &gt;:(<br>]]></description>
        <author>alexgrus</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93739</guid>
        <pubDate>Mon, 09 Dec 2002 08:48:42 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93739</link>
        <description><![CDATA[new: 1]]></description>
        <author>new</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93738</guid>
        <pubDate>Mon, 09 Dec 2002 06:47:19 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93738</link>
        <description><![CDATA[GrAnd: А всегда пользуюсь некоторой своей модификацией сортировки Шелла.<br>Более оптимального не видел, и память экономит и время мизерное<br><br>rgValue - массив значений<br>iNextOffset - размер элемента массива<br>iCount - количество элементов<br>gIndex - результирующий массив индексов<br><br><br>void inline XSort(const float* rgValue, const int iNextOffset, const int iCount, int* rgIndex)<br>{<br> &nbsp; &nbsp; &nbsp;for(int i=0; i&lt;iCount; i++) rgIndex[i] = i;<br> &nbsp; &nbsp; &nbsp;int iInd;<br> &nbsp; &nbsp; &nbsp;for (int h = iCount&gt;&gt;1; h; h&gt;&gt;=1) &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i=h; i&lt;iCount; i++) &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int j=i-h; j&gt;=0 &amp;&amp; (rgValue[rgIndex[j+h]*iNextOffset]&lt;rgValue[rgIndex[j]*iNextOffset]); j-=h)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iInd = rgIndex[j];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rgIndex[j] = rgIndex[j+h];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rgIndex[j+h] = iInd;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>}<br> ;D ;D ;D]]></description>
        <author>GrAnd</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93737</guid>
        <pubDate>Sat, 07 Dec 2002 23:51:54 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93737</link>
        <description><![CDATA[ADIDAS: Господа не мучайтесь вот готовый код QSort всё работает.<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br> &nbsp;SetArray = array of integer;<br>var<br> &nbsp;Form1: TForm1;<br> &nbsp;data:SetArray;<br> &nbsp;{ ******** }<br> &nbsp;oneProcent:integer;<br>implementation<br>{$R *.DFM}<br>procedure quicksort(var a: SetArray; Lo,Hi: integer);<br> &nbsp; &nbsp; &nbsp; &nbsp;procedure sort(l,r: integer);<br> &nbsp; &nbsp; &nbsp; &nbsp;var<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i,j,x,y: integer;<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i:=l; j:=r; x:=a[(l+r) DIV 2];<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;repeat<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while a[i]&lt;x do i:=i+1;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while x&lt;a[j] do j:=j-1;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if i&lt;=j then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;y:=a[i]; a[i]:=a[j]; a[j]:=y;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i:=i+1; j:=j-1;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;until i&gt;j;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Form1.Gauge1.Progress:=(j-(StrToInt(form1.Edit1.Text) div 2)) div OneProcent;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if l&lt;j then sort(l,j);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if i&lt;r then sort(i,r);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br>begin {quicksort};<br> &nbsp;sort(Lo,Hi);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var i:integer;<br>begin<br> &nbsp; &nbsp; SetLength(Data,StrToInt(Edit1.Text)+1);<br> &nbsp;Randomize;<br> &nbsp;for i:=1 to StrToInt(Edit1.Text) do data[i]:=Random(StrToInt(Edit1.Text)*2);<br><br> &nbsp; oneProcent:=((StrToInt(Edit1.Text)-1) div 100) div 2;<br> &nbsp;quicksort(data,1,StrToInt(Edit1.Text));<br><br> &nbsp;for i:=1 to StrToInt(Edit1.Text) do<br> &nbsp;begin<br> &nbsp; Table.Cells[0,i]:='# '+IntToStr(i);<br> &nbsp; Table.Cells[1,i]:=IntToStr(data[i]);<br> &nbsp; Gauge2.Progress:=i div (StrToInt(Edit1.Text) div 100);<br><br> &nbsp;end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp; &nbsp; &nbsp; &nbsp;Table.Cells[1,0]:='QuickSort';<br>end;<br><br>procedure TForm1.Edit1Change(Sender: TObject);<br>begin<br> &nbsp; &nbsp; Table.RowCount:=StrToInt(Edit1.Text)+1;<br>end;<br><br>end.<br>]]></description>
        <author>ADIDAS</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93736</guid>
        <pubDate>Thu, 05 Dec 2002 10:11:53 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93736</link>
        <description><![CDATA[DNick: Вообще-то для целых чисел самая быстрая сортировка - подсчетом (но гадина, самая расточительная в плане памяти)]]></description>
        <author>DNick</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93735</guid>
        <pubDate>Wed, 04 Dec 2002 00:08:01 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93735</link>
        <description><![CDATA[Shiru_Otaku: Я-же сказал - самый быстрый метод сортировки;) В основном для целых чисел... Поищи в инете алгоритм (bit sort, битовая сортировка), он очень простой (и единственно подходящий для задач типа сортировки полигонов итп - когда массивы очень большие, т.к. он делает всего-лишь разрядность*количество прогонов)...]]></description>
        <author>Shiru_Otaku</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93734</guid>
        <pubDate>Sun, 01 Dec 2002 21:10:16 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93734</link>
        <description><![CDATA[alexgrus: <div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <span class='tag-quote__quote-info'>Shiru_Otaku, 01.12.02, 03:05:47</span><div class='quote '>А как-же самый быстрый метод сортировки - bitsort?</div></div><br><br>А что это за метод такой.<br><br>Спасибо всем за участие, я наконец-то разобрался с QSort.<br>]]></description>
        <author>alexgrus</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93733</guid>
        <pubDate>Sun, 01 Dec 2002 00:05:47 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93733</link>
        <description><![CDATA[Shiru_Otaku: А как-же самый быстрый метод сортировки - bitsort?]]></description>
        <author>Shiru_Otaku</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93732</guid>
        <pubDate>Sat, 30 Nov 2002 23:51:53 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93732</link>
        <description><![CDATA[Rumata: мне кажется, что ты вызывал ее с единичкой вместо нуля]]></description>
        <author>Rumata</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93731</guid>
        <pubDate>Sat, 30 Nov 2002 23:49:51 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93731</link>
        <description><![CDATA[Rumata: у тебя траббл заключается в следующем....<br><br>надо вызывать свою процу именно так<br><div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&#60;br&#62;const&#60;br&#62;  N = 20;&#60;br&#62;var&#60;br&#62;  A: array[1..N] of Integer;&#60;br&#62;  I: Integer;&#60;br&#62;&#60;br&#62;begin&#60;br&#62;  A[ 1] := 38; A[ 2] :=  8; A[ 3] :=  3; A[ 4] := 45; A[ 5] := 12;&#60;br&#62;  A[ 6] := 89; A[ 7] := 15; A[ 8] := 21; A[ 9] :=  8; A[10] := 89;&#60;br&#62;  A[11] :=  7; A[12] := 34; A[13] :=  3; A[14] := 38; A[15] := 40;&#60;br&#62;  A[16] := 18; A[17] := 19; A[18] :=  5; A[19] :=  1; A[20] := 56;&#60;br&#62;&#60;br&#62;  for I := 1 to N do Write(A[I]:3); Writeln;&#60;br&#62;&#60;br&#62;  QuickSort(A, 0, N); // не забудь!!! именно [b]НОЛЬ[/b]&#60;br&#62;&#60;br&#62;  for I := 1 to N do Write(A[I]:3); Writeln;&#60;br&#62;  Writeln;&#60;br&#62;end.&#60;br&#62;</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>]]></description>
        <author>Rumata</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93730</guid>
        <pubDate>Thu, 28 Nov 2002 01:40:44 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93730</link>
        <description><![CDATA[alexgrus: По-моему я немного поторопился. &nbsp;:o<br>Изучив и протестировав алгоритм сортировки QuickS я пришел к выводу – а ошибочка то осталась. &nbsp; :-[<br><br>Это ошибка заключается в том, что первый элемент массива НЕ СОРТИРУЕТСЯ а каким то образом остается постоянно первым.<br><br>Помогите найти ошибку, или хотя бы намекните где она может быть.]]></description>
        <author>alexgrus</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93729</guid>
        <pubDate>Sun, 24 Nov 2002 01:10:37 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93729</link>
        <description><![CDATA[alexgrus: :D<br><br>Большое спасибо AleXXKSyS !!!<br>Я посмотрел код вроде разобрался, но чесно говоря я не ожидал что так быстро ответят.]]></description>
        <author>alexgrus</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93728</guid>
        <pubDate>Sat, 23 Nov 2002 08:00:18 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93728</link>
        <description><![CDATA[AleXXKSyS: Посмотри пример :<br>(* Sortirovca metodami vstavki, puzirka, viborki i bistroi sortirovki.<br> &nbsp; Puzirek: Prosmotr lineinogo massiva n! raz, v rezulitate cego<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sravnivaiutsa 2 sosednih elementa i v sluacae neobhodimosti<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;meniaiutsa mestami(vozrastanie ili ubivanie).<br> &nbsp; Biborka: Viborka maximalnogo elementa i ustanovca ego na 1 pozitiu,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dalee nahodim maximalnii v (n-1) ostavshihsea i ustanovca ego<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;na 2 pozitiu, i t.d(zavisimosti ot vozrastanie ili ubivanie).<br> &nbsp; Vstavca: Poisk 2-h elementov, kotorie otsortirovani, i vstavleaem mejdu<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nimi ostalinoi massiv, dalee sravnivaem sosednie elementi s<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;otsortirovannimi i meneaem mestami pri neobhodimosti i t.d.<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;do togo poka ne poluchim polnoistiu otsortirovanni massiv.<br> QuickSort: Samii optimalnii metod, v kotorom pri sortirovke sravnivaiutsea<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;naibolee dalinie kliuchi. Massiv recursivno delitsa popolam<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;i v poluchennih polovinkah proishodit sortirovca. &nbsp; &nbsp; &nbsp; &nbsp; *)<br>Program LabMPI2;<br>Uses &nbsp; &nbsp;Crt, Dos;<br>Const &nbsp; Max = 1500; &nbsp;{ Max=8000 }<br>Type &nbsp; &nbsp;MaxArray = array[1..Max] of Integer;<br>var &nbsp; i, j, T &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Integer;<br> &nbsp; &nbsp; &nbsp;A, BubbleSortArray,<br> &nbsp; &nbsp; &nbsp;SelectionSortArray,<br> &nbsp; &nbsp; &nbsp;QuickSortArray,<br> &nbsp; &nbsp; &nbsp;InsertSortArray &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : MaxArray;<br> &nbsp; &nbsp; &nbsp;hour0, hour1, min0, &nbsp;min1,<br> &nbsp; &nbsp; &nbsp;sec0, &nbsp;sec1, &nbsp;hund0, hund1 &nbsp;: Word;<br> &nbsp; &nbsp; &nbsp;SelectionTime, InsertTime,<br> &nbsp; &nbsp; &nbsp;BubbleTime, &nbsp; &nbsp;QuickTime &nbsp; &nbsp;: LongInt;<br> &nbsp; &nbsp; &nbsp;F &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : text;<br>Procedure BubbleSort(var _A: array of Integer);<br>begin<br> &nbsp;for I := High(_A) downto Low(_A) do<br> &nbsp; &nbsp;for J := Low(_A) to High(_A) - 1 do<br> &nbsp; &nbsp; &nbsp;if _A[J] &gt; _A[J + 1] then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;T := _A[J];<br> &nbsp; &nbsp; &nbsp; &nbsp;_A[J] := _A[J + 1];<br> &nbsp; &nbsp; &nbsp; &nbsp;_A[J + 1] := T;<br> &nbsp; &nbsp; &nbsp;end;<br>end;<br>Procedure SelectionSort(var _A: array of Integer);<br>begin<br> &nbsp;for I := Low(_A) to High(_A) - 1 do<br> &nbsp; &nbsp;for J := High(_A) downto I + 1 do<br> &nbsp; &nbsp; &nbsp;if _A[I] &gt; _A[J] then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;T := _A[I];<br> &nbsp; &nbsp; &nbsp; &nbsp;_A[I] := _A[J];<br> &nbsp; &nbsp; &nbsp; &nbsp;_A[J] := T;<br> &nbsp; &nbsp; &nbsp;end;<br>end;<br>Procedure QuickSort(var _A: array of Integer);<br><br> &nbsp;procedure QuickS(var _A: array of Integer; iLo, iHi: Integer);<br> &nbsp;var<br> &nbsp; &nbsp;Lo, Hi, Mid: Integer;<br> &nbsp;begin<br> &nbsp; &nbsp;Lo := iLo;<br> &nbsp; &nbsp;Hi := iHi;<br> &nbsp; &nbsp;Mid := _A[(Lo + Hi) div 2];<br> &nbsp; &nbsp;repeat<br> &nbsp; &nbsp; &nbsp;while _A[Lo] &lt; Mid do Inc(Lo);<br> &nbsp; &nbsp; &nbsp;while _A[Hi] &gt; Mid do Dec(Hi);<br> &nbsp; &nbsp; &nbsp;if Lo &lt;= Hi then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;T := _A[Lo];<br> &nbsp; &nbsp; &nbsp; &nbsp;_A[Lo] := _A[Hi];<br> &nbsp; &nbsp; &nbsp; &nbsp;_A[Hi] := T;<br> &nbsp; &nbsp; &nbsp; &nbsp;Inc(Lo);<br> &nbsp; &nbsp; &nbsp; &nbsp;Dec(Hi);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;until Lo &gt; Hi;<br> &nbsp; &nbsp;if Hi &gt; iLo then QuickS(_A, iLo, Hi);<br> &nbsp; &nbsp;if Lo &lt; iHi then QuickS(_A, Lo, iHi);<br> &nbsp;end;<br><br>begin<br> &nbsp;QuickS(_A, Low(_A), High(_A));<br>end;<br><br>Procedure InsertSort(Var _A: array of Integer);<br>begin<br> &nbsp;for i:=1 to Max do<br> &nbsp; begin<br> &nbsp; &nbsp;T := _A[i];<br> &nbsp; &nbsp;j := i-1;<br> &nbsp; &nbsp;while( (j&gt;=0)and(_A[j]&gt;T) )do<br> &nbsp; &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_A[j+1] := _A[j];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;j := j-1;<br> &nbsp; &nbsp; &nbsp; &nbsp; end;<br> &nbsp; &nbsp; &nbsp;_A[j+1] := T;<br> &nbsp; &nbsp;end;<br>end;<br><br>begin<br> &nbsp;ClrScr;<br> &nbsp;Randomize;<br> &nbsp;for i := 1 to Max do A[i] := random(Max);<br> &nbsp;for i := 1 to Max do<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;QuickSortArray[i] &nbsp; &nbsp; := A[i];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;InsertSortArray[i] &nbsp; &nbsp;:= A[i];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BubbleSortArray[i] &nbsp; &nbsp;:= A[i];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SelectionSortArray[i] := A[i];<br> &nbsp; &nbsp; end;<br><br> &nbsp;Assign(F, 'Sorting.txt');<br> &nbsp;ReWrite(F);<br> &nbsp;WriteLn('Press any key to begin sorting');<br> &nbsp;ReadKey;<br><br> &nbsp;GetTime(hour0,min0,sec0,hund0);<br> &nbsp;QuickSort(QuickSortArray);<br> &nbsp;GetTime(hour1,min1,sec1,hund1);<br> &nbsp;QuickTime := (sec1-sec0)*100 + hund1-hund0;<br><br> &nbsp;GetTime(hour0,min0,sec0,hund0);<br> &nbsp;SelectionSort(SelectionSortArray);<br> &nbsp;GetTime(hour1,min1,sec1,hund1);<br> &nbsp;SelectionTime := (sec1-sec0)*100 + hund1-hund0 ;<br><br> &nbsp;GetTime(hour0,min0,sec0,hund0);<br> &nbsp;BubbleSort(BubbleSortArray);<br> &nbsp;GetTime(hour1,min1,sec1,hund1);<br> &nbsp;BubbleTime := (sec1-sec0)*100 + hund1-hund0;<br><br> &nbsp;GetTime(hour0,min0,sec0,hund0);<br> &nbsp;InsertSort(InsertSortArray);<br> &nbsp;GetTime(hour1,min1,sec1,hund1);<br> &nbsp;InsertTime := (sec1-sec0)*100 + hund1-hund0;<br><br> &nbsp;WriteLn(F, ' Quick &nbsp;Select &nbsp;Bubble &nbsp;Insert &nbsp;UnSorted');<br> &nbsp;for i := 1 to Max do<br> &nbsp; &nbsp; &nbsp; &nbsp; WriteLn(F, QuickSortArray[i]:6, &nbsp; &nbsp;' &nbsp;',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SelectionSortArray[i]:6,' &nbsp;',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BubbleSortArray[i]:6, &nbsp; ' &nbsp;',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;InsertSortArray[i]:6, &nbsp; ' &nbsp;', A[i]:6);<br> &nbsp;Close(F);<br> &nbsp;WriteLn('QuickTime &nbsp; &nbsp; = ', QuickTime,' msec');<br> &nbsp;WriteLn('InsertTime &nbsp; &nbsp;= ', InsertTime,' msec');<br> &nbsp;WriteLn('SelectionTime = ', SelectionTime,' msec');<br> &nbsp;WriteLn('BubbleTime &nbsp; &nbsp;= ', BubbleTime,' msec');<br> &nbsp;ReadKey;<br>end.]]></description>
        <author>AleXXKSyS</author>
        <category>Алгоритмы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93727</guid>
        <pubDate>Sat, 23 Nov 2002 04:22:41 +0000</pubDate>
        <title>Сортировка</title>
        <link>https://forum.sources.ru/index.php?showtopic=9719&amp;view=findpost&amp;p=93727</link>
        <description><![CDATA[alexgrus: Помогите, найти ошибку в этом коде (Я не ленивый у меня просто не хватает времени). Ошибка заключается в следующем: сортируя массив:<br>A[1] := 38; A[2] := 8; A[3] := 3; A[4] := 45; A[5] := 12;<br>A[6] := 89; A[7] := 15; A[8] := 21; A[9] := 8; A[10] := 89;<br>A[11] := 7; A[12] := 34; A[13] := 3; A[14] := 38; A[15] := 40;<br>A[16] := 18; A[17] := 19; A[18] := 5; A[19] := 1; A[20] := 56;<br>при помощи этого кода у меня получается: 38, 1, 3, 5, 7, 3, 8, 8, 12, 15, 18, 19, 21, 34, 38, 40, 56, 89, 45, 89.<br><br>И если возможно, подскажите, может быть есть более эффективный способ сортировки массива (желательно оптимизируя этот код).<br><br> procedure TForm1.InsertSort(var A: array of integer; ABeg, AEnd: integer);<br> var CountBeg, CountEnd, Temp: integer;<br> begin<br> &nbsp;CountBeg := ABeg + 1;<br> &nbsp;while CountBeg &lt;= AEnd do<br> &nbsp;begin<br> &nbsp; Temp := A[CountBeg];<br> &nbsp; CountEnd := CountBeg - 1;<br> &nbsp; while (CountEnd &gt;= ABeg) and (A[CountEnd] &gt; Temp) do<br> &nbsp; begin<br> &nbsp; &nbsp;A[CountEnd + 1] := A[CountEnd];<br> &nbsp; &nbsp;CountEnd := CountEnd - 1;<br> &nbsp; end;<br> &nbsp; A[CountEnd + 1] := Temp;<br> &nbsp; CountBeg := CountBeg + 1;<br> &nbsp;end;<br> end;<br> <br> function TForm1.Partition(var A: array of integer; ABeg, AEnd: integer): integer;<br> var<br> &nbsp;CountBeg, CountEnd,<br> &nbsp;Pivot,<br> &nbsp;Center,<br> &nbsp;Temp: integer;<br> begin<br> &nbsp;Center := ABeg + ((AEnd - ABeg) div 2);<br> &nbsp;Pivot := A[Center];<br> &nbsp;A[Center] := A[ABeg];<br> &nbsp;CountBeg := ABeg + 1;<br> &nbsp;CountEnd := AEnd;<br> &nbsp;while CountBeg &lt; CountEnd do<br> &nbsp;begin<br> &nbsp; &nbsp;while (CountBeg &lt; CountEnd) and (Pivot &gt; a[CountBeg]) do<br> &nbsp; &nbsp; CountBeg := CountBeg + 1;<br> &nbsp; &nbsp;while (CountBeg &lt;= CountEnd) and (Pivot &lt; a[CountEnd]) do<br> &nbsp; &nbsp; CountEnd := CountEnd - 1;<br> &nbsp; &nbsp;//Переставляем элементы местами<br> &nbsp; &nbsp;Temp := A[CountBeg];<br> &nbsp; &nbsp;A[CountBeg] := A[CountEnd];<br> &nbsp; &nbsp;A[CountEnd] := Temp;<br> &nbsp; &nbsp;CountEnd := CountEnd - 1;<br> &nbsp; &nbsp;CountBeg := CountBeg + 1;<br> &nbsp;end;<br> &nbsp;A[ABeg] := A[CountEnd];<br> &nbsp;A[CountEnd] := Pivot;<br> &nbsp;Partition := CountEnd;<br> end;<br><br> procedure TForm1.QuickSort(var A: array of integer; ABeg, AEnd: integer);<br> var Center: integer;<br> begin<br> &nbsp;while ABeg &lt; AEnd do<br> &nbsp;begin<br> &nbsp; if (AEnd - ABeg) &lt;= 12 then begin<br> &nbsp; &nbsp;InsertSort(A, ABeg, AEnd);<br> &nbsp; &nbsp;break;<br> &nbsp; end<br> &nbsp; else begin<br> &nbsp; &nbsp;Center := Partition(A, ABeg, AEnd);<br> &nbsp; &nbsp;if (Center - ABeg) &lt;= (AEnd - Center) then begin<br> &nbsp; &nbsp; QuickSort(A, ABeg, Center - 1);<br> &nbsp; &nbsp; ABeg := Center + 1;<br> &nbsp; &nbsp;end<br> &nbsp; &nbsp; else begin<br> &nbsp; &nbsp; &nbsp;QuickSort(A, Center + 1, AEnd);<br> &nbsp; &nbsp; &nbsp;AEnd := Center - 1;<br> &nbsp; &nbsp; end;<br> &nbsp; end;<br><br> &nbsp;end;<br> end;<br><br>В принципе код не сложный, поэтому я не стал его комментировать.<br>]]></description>
        <author>alexgrus</author>
        <category>Алгоритмы</category>
      </item>
	
      </channel>
      </rss>
	