<?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=300880&amp;view=findpost&amp;p=2572623</guid>
        <pubDate>Mon, 19 Apr 2010 11:00:59 +0000</pubDate>
        <title>Segmentation fault and exitcode 216</title>
        <link>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572623</link>
        <description><![CDATA[Vesper: кстати, <strong class='tag-b'>MacClaus</strong>, поймал твою ошибку. Она возникает, если ты сравниваешь два равных числа, не равных нулю, программа доходит до последнего знака, сравнивает, они равны, потом идет переход по next, а там уже nil, и ты следующим оператором пытаешься получить nil^, здесь и вылетает GPF. Турбо-Паскаль не имеет GPF как такового, поэтому что-то он у тебя &quot;сортирует&quot;. Вот этот кусок:<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">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; while (x.ch^.c = y.ch^.c) and (x.ch&#60;&#62;nil) and (y.ch&#60;&#62;nil) do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.ch:=x.ch^.next;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y.ch:=y.ch^.next;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if x.ch^.c &#60; y.ch^.c then fl:=false else fl:=true;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; end;</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script>переписываешь так:<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">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; while (x.ch&#60;&#62;nil) and (y.ch&#60;&#62;nil) do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if x.ch^.c&#60;&#62;y.ch^.c then begin </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if x.ch^.c &#60; y.ch^.c then fl:=false else fl:=true;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break {выход из цикла while. Учись, кстати, пользоваться}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.ch:=x.ch^.next;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y.ch:=y.ch^.next;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if (x.ch=nil) or (y.ch=nil) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; compare:=false; </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; end;</div><div class="code_line">{числа равны, а делать что-то надо. В этом случае оба указателя будут nil, а если только один, </div><div class="code_line">то ты напортачил при вводе чисел в память или при вычислении значений B[i].n}</div></ol></div></div></div></div>В общем случае, если ты переходишь на следующее звено списка, сначала должна идти проверка на NIL, а потом доступ к значениям.]]></description>
        <author>Vesper</author>
        <category>Pascal</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572213</guid>
        <pubDate>Sun, 18 Apr 2010 21:32:25 +0000</pubDate>
        <title>Segmentation fault and exitcode 216</title>
        <link>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572213</link>
        <description><![CDATA[Romtek: <strong class='tag-b'>MacClaus</strong>, прикрепи файл входных данных.]]></description>
        <author>Romtek</author>
        <category>Pascal</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572172</guid>
        <pubDate>Sun, 18 Apr 2010 19:36:45 +0000</pubDate>
        <title>Segmentation fault and exitcode 216</title>
        <link>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572172</link>
        <description><![CDATA[volvo877: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=300880&view=findpost&p=2572131'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>MacClaus &#064; <time class="tag-quote__quoted-time" datetime="2010-04-18T18:52:44+00:00">18.04.10, 18:52</time></span><div class='quote '>в турбопаскале этот же алгоритм сортирует данную последовательность, а во freepascal&#39;e нет</div></div>Программа на Турбо-Паскале компилировалась со всеми включенными опциями? (контроль индексов? контроль переполнения? контроль стека?)<br>
<br>
Ты файл с данными, которые &quot;прошли сортировку&quot; (именно в кавычках, потому что если ты портишь какую-то информацию, что очень часто встречается при отключенных опциях в Турбо-Паскале; FPC такого не позволяет - он тут же вылетает с SF) привел? Как же ты тогда можешь утверждать, что TP код сортирует? Так и пиши: &quot;МНЕ КАЖЕТСЯ, что У МЕНЯ код сортирует данные&quot;. Не надо обобщать...<br>
<br>
Не хочешь помощи - ищи проблему сам... Я ЗА ТЕБЯ подбирать данные, на которых программа вылетает, не собираюсь...]]></description>
        <author>volvo877</author>
        <category>Pascal</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572131</guid>
        <pubDate>Sun, 18 Apr 2010 18:52:44 +0000</pubDate>
        <title>Segmentation fault and exitcode 216</title>
        <link>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572131</link>
        <description><![CDATA[MacClaus: <strong class='tag-b'>Vesper</strong>, советы учту. Просто, несмотря на все недочеты, вводится все нормально и даже сортируется в турбо. Но вот во freepascal он при дебаге обнаруживает через некоторое время ошибку Segmentation fault в строке if x.ch^.c &lt; y.ch^.c then fl:=false else fl:=true почти в конце процедуры compare, просто я не могу понять, что ему не нравится, если данные введены корректно, в турбопаскале этот же алгоритм сортирует данную последовательность, а во freepascal&#39;e нет. Просто в чем может быть причина ??]]></description>
        <author>MacClaus</author>
        <category>Pascal</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572118</guid>
        <pubDate>Sun, 18 Apr 2010 18:39:14 +0000</pubDate>
        <title>Segmentation fault and exitcode 216</title>
        <link>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572118</link>
        <description><![CDATA[Vesper: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=300880&view=findpost&p=2572103'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>MacClaus &#064; <time class="tag-quote__quoted-time" datetime="2010-04-18T17:59:21+00:00">18.04.10, 17:59</time></span><div class='quote '>new(p); p:=B[i].ch; </div></div>во-первых у тебя здесь утечка памяти. Ты выделяешь память для P, и тут же присваиваешь P чему-то еще. Это у тебя в трех местах, во внешнем коде, внутри compare и внутри vvod(B)<br>
<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=300880&view=findpost&p=2572103'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>MacClaus &#064; <time class="tag-quote__quoted-time" datetime="2010-04-18T17:59:21+00:00">18.04.10, 17:59</time></span><div class='quote '>procedure swap(var x,y:elem); var z:elem; begin new(z.ch); </div></div>здесь не нужен new(z.ch) - тебе не нужно выделять какую-то память для обмена местами двух ссылок на данные. Ты на некоторое время получаешь две ссылки на одно и то же место в куче, и всё.<br>
<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=300880&view=findpost&p=2572103'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>MacClaus &#064; <time class="tag-quote__quoted-time" datetime="2010-04-18T17:59:21+00:00">18.04.10, 17:59</time></span><div class='quote '>vvod:=&#39;&#39;; </div></div>зачем тебе объявлять vvod функцией? достаточно объявить её процедурой, все равно ты не используешь значение, возвращаемое из vvod(B).<br>
<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=300880&view=findpost&p=2572103'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>MacClaus &#064; <time class="tag-quote__quoted-time" datetime="2010-04-18T17:59:21+00:00">18.04.10, 17:59</time></span><div class='quote '>if s=&#39;0&#39; then B[i].zero:=B[i].zero and true else B[i].zero:=false; </div></div>индийский код. Правильно (по смыслу, ты пытаешься вынести признак нуля в B[i ].zero) так: if s&lt;&gt;&#39;0&#39; then b[i ].zero:=false; Кроме того, отсутствует проверка на принадлежность прочитанного символа множеству цифр. Если там что-то вроде #13, #9, #26 или просто буквы, или даже еще один минус, у тебя в разряде появится несусветная величина.<br>
<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=300880&view=findpost&p=2572103'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>MacClaus &#064; <time class="tag-quote__quoted-time" datetime="2010-04-18T17:59:21+00:00">18.04.10, 17:59</time></span><div class='quote '>new(B[i].ch^.next);<br>
 B[i].ch:=B[i].ch^.next; <br>
B[i].ch^.c:=ord(s)-ord(&#39;0&#39;); <br>
B[i].ch^.next:=nil</div></div>Это правильный кусок, с учетом того, что ты сохранил первый элемент списка в P, хотя и не совсем обычный способ использования переменных.<br>
<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=300880&view=findpost&p=2572103'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>MacClaus &#064; <time class="tag-quote__quoted-time" datetime="2010-04-18T17:59:21+00:00">18.04.10, 17:59</time></span><div class='quote '>repeat inc(i); fl:=true; read(s); if (s&lt;&gt;&#39; &#39;) and (s&lt;&gt;&#39;.&#39;) then begin</div></div>Для приличия нужно очистить (инициализировать, заполнить стартовыми значениями) всю запись B[i ]. В некоторых реализациях компилятора начальный сегмент данных может не заполняться нулями в начале работы программы, и тогда в переменных будет жуткий мусор, а ты опираешься по меньшей мере в двух местах на то, что в начале работы с записью в B[i ].поле лежит ноль.<br>
<br>
Теперь процедура сравнения. Если x.n меньше нуля, а y.n больше нуля, понятно, что сравнивать нечего - и так ясно, что больше :) используй конструкцию exit для выхода из процедуры со значением. <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">if x.sgn &#60;&#62; y.sgn then begin</div><div class="code_line">&nbsp;if x.sgn=false then compare:=true else compare:=false;</div><div class="code_line">&nbsp;exit;</div><div class="code_line">end else ....</div></ol></div></div></div></div>Счетчик сравнений ты так или иначе увеличиваешь, поэтому логичнее их увеличивать сразу после входа в функцию. Раз вошел, значит сравнил. И вообще, внимательно разберись с ветвлениями в этом месте. У тебя минимум шесть вложенных if&#39;ов, в части из которых идет присвоение значения результату compare, которое имеет смысл сразу же обозначить и выдать наружу (присвоил и сразу exit) - и нагляднее, и удобнее баги ловить.]]></description>
        <author>Vesper</author>
        <category>Pascal</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572108</guid>
        <pubDate>Sun, 18 Apr 2010 18:15:02 +0000</pubDate>
        <title>Segmentation fault and exitcode 216</title>
        <link>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572108</link>
        <description><![CDATA[volvo877: <strong class='tag-b'>MacClaus</strong>, файл данных присоедини... Если так не прилепится - то заархивируй.<br>
<br>
Кстати,, если используешь FPC, подключи <strong class='tag-b'>первыми</strong> модули <strong class='tag-b'>heaptrc</strong> и <strong class='tag-b'>lineinfo</strong>, и получишь точное указание места. где произошла ошибка. Будет гораздо проще искать причину...]]></description>
        <author>volvo877</author>
        <category>Pascal</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572105</guid>
        <pubDate>Sun, 18 Apr 2010 18:07:49 +0000</pubDate>
        <title>Segmentation fault and exitcode 216</title>
        <link>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572105</link>
        <description><![CDATA[Vesper: хотя бы код модуля, где генерируешь строку, и код модуля, который вырает ошибку.<br>кстати, вроде как 216 это не код компиляции, а ошибка периода исполнения, поиск выдал GPF (ошибка доступа по ссылке), скорее всего у тебя в каком-то месте x.ch=NIL]]></description>
        <author>Vesper</author>
        <category>Pascal</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572103</guid>
        <pubDate>Sun, 18 Apr 2010 17:59:21 +0000</pubDate>
        <title>Segmentation fault and exitcode 216</title>
        <link>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572103</link>
        <description><![CDATA[MacClaus: код всей программы ?? <br>
<br>
<span class="tag-color tag-color-named" data-value="gray" style="color: gray"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2010-04-18T18:05:10+00:00">18.04.10, 18:05</time></span></span><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">program sortirovki;</div><div class="code_line">{$s-}</div><div class="code_line">{$r-}</div><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp; &nbsp; list=^zveno;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; zveno=record</div><div class="code_line">&nbsp;&nbsp; &nbsp; c:byte;</div><div class="code_line">&nbsp;&nbsp; &nbsp; next:list</div><div class="code_line">&nbsp;&nbsp; &nbsp; end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; elem=record</div><div class="code_line">&nbsp;&nbsp; &nbsp; sgn:boolean;</div><div class="code_line">&nbsp;&nbsp; &nbsp; n:integer;</div><div class="code_line">&nbsp;&nbsp; &nbsp; zero:boolean;</div><div class="code_line">&nbsp;&nbsp; &nbsp; ch:list;</div><div class="code_line">&nbsp;&nbsp; &nbsp; kz:integer</div><div class="code_line">&nbsp;&nbsp; &nbsp; end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; structure=array [1..1500] of elem;</div><div class="code_line">&nbsp;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp; &nbsp;B:structure;</div><div class="code_line">&nbsp;&nbsp; &nbsp;i,N,hs,M,l,prc,src,prh,srh,T:longint;</div><div class="code_line">&nbsp;&nbsp; &nbsp;c:char;</div><div class="code_line">&nbsp;&nbsp; &nbsp;p:list;</div><div class="code_line">&nbsp;&nbsp; &nbsp;vsgn:boolean;</div><div class="code_line">function compare(var x,y:elem):boolean; &nbsp;{true, esli x&#62;y}</div><div class="code_line">var px,py:list;</div><div class="code_line">&nbsp;&nbsp; &nbsp;fl:boolean;</div><div class="code_line">begin</div><div class="code_line">if x.sgn &#60;&#62; y.sgn then</div><div class="code_line">&nbsp;if x.sgn=false then compare:=true else compare:=false else</div><div class="code_line">&nbsp;&nbsp; if x.n&#60;&#62;y.n then</div><div class="code_line">&nbsp;&nbsp; &nbsp; if x.n &#60; y.n then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; if x.sgn=false then compare:=false else compare:=true else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if x.sgn=false then compare:=true else compare:=false else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; new(px);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; new(py);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; px:=x.ch;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; py:=y.ch;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if x.ch^.c=0 then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; repeat</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.ch:=x.ch^.next;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; until x.ch^.c&#60;&#62;0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if y.ch^.c=0 then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; repeat</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y.ch:=y.ch^.next;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; until y.ch^.c&#60;&#62;0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if x.ch^.c &#60; y.ch^.c then fl:=false else fl:=true;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; while (x.ch^.c = y.ch^.c) and (x.ch&#60;&#62;nil) and (y.ch&#60;&#62;nil) do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x.ch:=x.ch^.next;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y.ch:=y.ch^.next;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if x.ch^.c &#60; y.ch^.c then fl:=false else fl:=true;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; x.ch:=px;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; y.ch:=py;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (x.sgn=false) and fl &nbsp;then compare:=true else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if (x.sgn=false) and not fl then compare:=false else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (x.sgn=true) and fl then compare:=false else compare:=true;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; end;</div><div class="code_line">srh:=srh+1;</div><div class="code_line">src:=src+1;</div><div class="code_line">end;</div><div class="code_line">procedure swap(var x,y:elem);</div><div class="code_line">var z:elem;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;new(z.ch);</div><div class="code_line">&nbsp;&nbsp;z.n:=x.n;</div><div class="code_line">&nbsp;&nbsp;z.kz:=x.kz;</div><div class="code_line">&nbsp;&nbsp;z.sgn:=x.sgn;</div><div class="code_line">&nbsp;&nbsp;z.zero:=x.zero;</div><div class="code_line">&nbsp;&nbsp;z.ch:=x.ch;</div><div class="code_line">&nbsp;&nbsp;x.n:=y.n;</div><div class="code_line">&nbsp;&nbsp;x.kz:=y.kz;</div><div class="code_line">&nbsp;&nbsp;x.sgn:=y.sgn;</div><div class="code_line">&nbsp;&nbsp;x.zero:=y.zero;</div><div class="code_line">&nbsp;&nbsp;x.ch:=y.ch;</div><div class="code_line">&nbsp;&nbsp;y.n:=z.n;</div><div class="code_line">&nbsp;&nbsp;y.kz:=z.kz;</div><div class="code_line">&nbsp;&nbsp;y.sgn:=z.sgn;</div><div class="code_line">&nbsp;&nbsp;y.zero:=z.zero;</div><div class="code_line">&nbsp;&nbsp;y.ch:=z.ch;</div><div class="code_line">&nbsp;&nbsp;prh:=prh+1;</div><div class="code_line">&nbsp;&nbsp;prc:=prc+1;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure heapify(var B:structure;j:integer);</div><div class="code_line">var max:integer;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;if (2*j &#60;= hs) and (not compare(B[j],B[2*j])) then max:=2*j else max:=j;</div><div class="code_line">&nbsp;&nbsp;if &nbsp;(2*j+1 &#60;= hs) and (not compare(B[max],B[2*j+1])) then max:=2*j+1;</div><div class="code_line">&nbsp;&nbsp;if j &#60;&#62; max then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;swap(B[j],B[max]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;heapify(B,max);</div><div class="code_line">&nbsp;&nbsp;end</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure heapsort(var B:structure);</div><div class="code_line">var i,l:integer;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;for i:=hs div 2 downto 1 do</div><div class="code_line">&nbsp;&nbsp; &nbsp;heapify(B,i);</div><div class="code_line">&nbsp;&nbsp; &nbsp;{for l:=1 to N do</div><div class="code_line">&nbsp;&nbsp; &nbsp; write(a[l],&#39; &#39;);}</div><div class="code_line">&nbsp;&nbsp;for i:=hs downto 2 do</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;swap(B[1],B[i]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;dec(hs);</div><div class="code_line">&nbsp;&nbsp; &nbsp;heapify(B,1);</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure chsort(var B:structure);</div><div class="code_line">var i,j:integer;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;i:=1;</div><div class="code_line">&nbsp;&nbsp;while i&#60;N do</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;if compare(B[i],B[i+1]) then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; j:=i;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; while (not compare(B[j+1],B[j])) and (j &#60;&#62; 0) do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; swap(B[j],B[j+1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; dec(j);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; inc(i);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end else inc(i);</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">function vvod(var B:structure):string;</div><div class="code_line">var s:char;</div><div class="code_line">&nbsp;&nbsp; &nbsp;fl:boolean;</div><div class="code_line">&nbsp;&nbsp; &nbsp;i:integer;</div><div class="code_line">&nbsp;&nbsp; &nbsp;p:list;</div><div class="code_line">&nbsp;&nbsp; &nbsp;cp:boolean;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;i:=0;</div><div class="code_line">&nbsp;&nbsp;repeat</div><div class="code_line">&nbsp;&nbsp; &nbsp;inc(i);</div><div class="code_line">&nbsp;&nbsp; &nbsp;fl:=true;</div><div class="code_line">&nbsp;&nbsp; &nbsp;read(s);</div><div class="code_line">&nbsp;&nbsp; &nbsp;if (s&#60;&#62;&#39; &#39;) and (s&#60;&#62;&#39;.&#39;) then</div><div class="code_line">&nbsp;&nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if s=&#39;-&#39; then begin read(s);B[i].sgn:=true; end else B[i].sgn:=false;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (s=&#39;0&#39;) and fl then B[i].kz:=B[i].kz+1 else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;B[i].n:=B[i].n+1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;fl:=false</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if s&#60;&#62;&#39;0&#39; then B[i].zero:=false else B[i].zero:=true;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;new(B[i].ch);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;B[i].ch^.c:=ord(s)-ord(&#39;0&#39;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;B[i].ch^.next:=nil;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;new(p);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;p:=B[i].ch;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;repeat</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;read(s);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (s&#60;&#62;&#39; &#39;) and (s&#60;&#62;&#39;.&#39;) then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if s=&#39;0&#39; then B[i].zero:=B[i].zero and true else B[i].zero:=false;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (s=&#39;0&#39;) and fl then B[i].kz:=B[i].kz+1</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;B[i].n:=B[i].n+1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fl:=false</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new(B[i].ch^.next);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;B[i].ch:=B[i].ch^.next;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;B[i].ch^.c:=ord(s)-ord(&#39;0&#39;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;B[i].ch^.next:=nil</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;until (s=&#39; &#39;) or (s=&#39;.&#39;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;B[i].ch:=p;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;T:=T+1;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;until (s=&#39;.&#39;);</div><div class="code_line">vvod:=&#39;&#39;;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">begin</div><div class="code_line">T:=0;</div><div class="code_line">assign(input,&#39;input.txt&#39;);</div><div class="code_line">assign(output,&#39;output.txt&#39;);</div><div class="code_line">reset(input);</div><div class="code_line">rewrite(output);</div><div class="code_line">src:=0;</div><div class="code_line">prc:=0;</div><div class="code_line">srh:=0;</div><div class="code_line">prh:=0;{</div><div class="code_line">&nbsp;&nbsp;writeln(&#39;Vvedite razmer massiva&#39;);</div><div class="code_line">&nbsp;&nbsp;read(N);</div><div class="code_line">&nbsp;&nbsp;writeln(&#39;Vvedite elementi massiva&#39;);</div><div class="code_line">&nbsp;&nbsp;for i:=1 to N do</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;read(x[i]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;y[i]:=x[i];</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;chsort(x);</div><div class="code_line">&nbsp;&nbsp; &nbsp;writeln;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp;writeln(&#39;Kolichestvo sravnenii i prisvaivanii dlya chelnok &#39;,src,&#39; &#39;,prc);</div><div class="code_line">&nbsp;&nbsp;writeln(&#39;Kolichestvo sravnenii i prisvaivanii dlya heapsort &#39;,srh,&#39; &#39;,prh);</div><div class="code_line">&nbsp;&nbsp;writeln(&#39;Rezultati sortirovki: 1)chelnok for X, 2)heapsort for Y&#39;);</div><div class="code_line">&nbsp;&nbsp;for i:=1 to N do</div><div class="code_line">&nbsp;&nbsp; &nbsp;write(x[i],&#39; &#39;);</div><div class="code_line">&nbsp;&nbsp; &nbsp;writeln;</div><div class="code_line">&nbsp;&nbsp;for i:=1 to N do</div><div class="code_line">&nbsp;&nbsp; &nbsp;write(y[i],&#39; &#39;); }</div><div class="code_line">&nbsp;&nbsp;{probi vivoda}</div><div class="code_line">&nbsp;&nbsp;vvod(B);</div><div class="code_line">&nbsp;&nbsp;hs:=T;</div><div class="code_line">&nbsp;&nbsp;N:=T;</div><div class="code_line">&nbsp;&nbsp;heapsort(B);</div><div class="code_line">&nbsp;&nbsp;{chsort(B);}</div><div class="code_line">&nbsp;&nbsp;{writeln(prh,&#39; &#39;,srh);}</div><div class="code_line">&nbsp;&nbsp;{writeln(B[1].ch^.c);}</div><div class="code_line">&nbsp;&nbsp;{writeln(compare(B[1],B[2]));}</div><div class="code_line">&nbsp;&nbsp;{writeln(B[1].n,&#39; &#39;,B[2].n);}</div><div class="code_line">&nbsp;&nbsp;{writeln(B[1].ch^.next^.next^.c);}</div><div class="code_line">&nbsp;&nbsp;{writeln(compare(B[1],B[3]));}</div><div class="code_line">&nbsp;&nbsp;{writeln(T);}</div><div class="code_line">&nbsp;&nbsp;for i:=1 to T do</div><div class="code_line">&nbsp;&nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;new(p);</div><div class="code_line">&nbsp;&nbsp; &nbsp;p:=B[i].ch;</div><div class="code_line">&nbsp;&nbsp; &nbsp;vsgn:=true;</div><div class="code_line">&nbsp;&nbsp; &nbsp;while (B[i].ch&#60;&#62;nil) do</div><div class="code_line">&nbsp;&nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (B[i].sgn=true) and vsgn then begin vsgn:=false; write(&#39;-&#39;) end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;write(B[i].ch^.c);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;B[i].ch:=B[i].ch^.next;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;write(&#39; &#39;);</div><div class="code_line">&nbsp;&nbsp; &nbsp;B[i].ch:=p;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp;{end probi}</div><div class="code_line">readln;</div><div class="code_line">readln;</div><div class="code_line">close(input);</div><div class="code_line">close(output);</div><div class="code_line">end.</div></ol></div></div></div></div>]]></description>
        <author>MacClaus</author>
        <category>Pascal</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572099</guid>
        <pubDate>Sun, 18 Apr 2010 17:55:36 +0000</pubDate>
        <title>Segmentation fault and exitcode 216</title>
        <link>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572099</link>
        <description><![CDATA[Vesper: ошибка в 84й строке<br>то есть, просим код в студию.]]></description>
        <author>Vesper</author>
        <category>Pascal</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572097</guid>
        <pubDate>Sun, 18 Apr 2010 17:50:30 +0000</pubDate>
        <title>Segmentation fault and exitcode 216</title>
        <link>https://forum.sources.ru/index.php?showtopic=300880&amp;view=findpost&amp;p=2572097</link>
        <description><![CDATA[MacClaus: Привет всем. Пишу на паскале программу сортировки чисел произвольной длины. Числа храню в списках поциферно. Начинал писать программу на TP, но вскоре столкнулся с проблемой нехватки памяти (сортировал, например, 1000 чисел, в каждом из которых 1000 цифр). Вследствие этого перешел на FP. Тут наблюдаю следующее: все вроде работает, но на некоторых не длинных последовательностях довольно коротких чисел FP выдает ошибку компиляции с exitcode 216, в то время, как в турбопаскале эта же программа данную последовательность сортирует. Еще раз напомню, что на TP не могу вернуться, т.к.не хватает памяти при сортировке больших последовательностей, с которыми успешно справляется freePascal.Т.е ситуация плохая - и там и там скажем так БАГ. При debug&#39;e выяснилось, что ошибка в процедуре сравнения чисел, причем выскакивает ошибка Segmentation fault не на первых же числах при сортировке. Недоумеваю, как это победить. Что может быть не так? Ошибку пишет на строке: if x.ch^.c&lt;y.ch^.c then fl:=false else fl:=true - в данной строке сравниваю чиса покоординатно, т.е. x.ch - ссылка на один из разрядов числа (описал, чтобы вкратце стало понятно). Вроде бы &quot;странностей&quot; с указателями не допускаю... Подскажите что-нибудь, пожалуйста. А то такой ступор уже долго...]]></description>
        <author>MacClaus</author>
        <category>Pascal</category>
      </item>
	
      </channel>
      </rss>
	