<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'arranging sorting an array' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'arranging sorting an array' posted on the 'Pascal' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Tue, 18 Jun 2013 15:57:53 -0700</pubDate>
    <lastBuildDate>Tue, 18 Jun 2013 15:57:53 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>arranging sorting an array</title>
      <link>http://www.programmersheaven.com/mb/pasprog/412937/412937/arranging-sorting-an-array/</link>
      <description>Hi!&lt;br /&gt;
i am having trouble sorting  an array using a for loop.&lt;br /&gt;
the problem occurs when using iterations i and i+1&lt;br /&gt;
&lt;br /&gt;
for example &lt;br /&gt;
count:=0&lt;br /&gt;
for i:=0 to count do begin&lt;br /&gt;
if a[i] &amp;gt; a[i+1] then begin&lt;br /&gt;
....&lt;br /&gt;
&lt;br /&gt;
end &lt;br /&gt;
count+1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
problem is when the for loops reaches the LAST array value i , i+1 does not exist hence the problem.&lt;br /&gt;
I have tried using &lt;br /&gt;
" for i:=0 to count-1 do begin"&lt;br /&gt;
this does not help.&lt;br /&gt;
&lt;br /&gt;
any suggestions?&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/412937/412937/arranging-sorting-an-array/</guid>
      <pubDate>Tue, 02 Feb 2010 23:46:55 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: arranging sorting an array</title>
      <link>http://www.programmersheaven.com/mb/pasprog/412937/413012/re-arranging-sorting-an-array/#413012</link>
      <description>&lt;pre class="sourcecode"&gt;&lt;span style="color: Blue;"&gt;const array_size=10;

var t:array[1..array_size] of integer;
    i,j:byte;

procedure swap(var a,b:integer);
 begin
  a:=a xor b;
  b:=a xor b;
  a:=a xor b;
 end;

begin
 for i:=1 to array_size do begin
  write('Enter element no. ',i:2,': ');readln(t[i]);
 end;

 for i:=array_size downto 2 do  {Simple bubble sort}
  for j:=1 to i do
   if t[i]&amp;gt;t[j] then swap(t[i],t[j]);

 for i:=1 to array_size do
  writeln(i:2,': ',t[i]);
 readln;
end.&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/412937/413012/re-arranging-sorting-an-array/#413012</guid>
      <pubDate>Wed, 03 Feb 2010 17:18:09 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: arranging sorting an array</title>
      <link>http://www.programmersheaven.com/mb/pasprog/412937/413063/re-arranging-sorting-an-array/#413063</link>
      <description>hi!&lt;br /&gt;
i have listed the entire code for reference at the bottom.&lt;br /&gt;
&lt;br /&gt;
however I have tried something similar to what you suggested&lt;br /&gt;
I am still having the trouble of the sorting 'jumping ahead'.&lt;br /&gt;
the problem part is &lt;br /&gt;
&lt;pre class="sourcecode"&gt;

count :=1
begin
... values are entered


for i:=0 to count do begin

if CustomerSalary[i] &amp;gt; CustomerSalary[count] then begin
&amp;lt;arrays are sorted here&amp;gt;
tmpCustomerName:= CustomerName[i];
tmpCustomerLoan:= CustomerLoan[i];
tmpCustomerSalary:= CustomerSalary[i];

CustomerName[i]:= CustomerName[count];
CustomerLoan[i]:= CustomerLoan[count];
CustomerSalary[i]:= CustomerSalary[count];

CustomerName[count]:= tmpCustomerName;
CustomerLoan[count]:= tmpCustomerLoan;
CustomerSalary[count]:= tmpCustomerSalary;

end;
end;
count is incremented here

end.
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
                Program ;


var CustomerName: array[1..25] of string;
var CustomerLoan: array[1..25] of integer;
var CustomerSalary: array[1..25] of integer;
var i,j: integer;
var tmpCustomerName:string;
var tmpCustomerLoan:integer;
var tmpCustomerSalary:integer;
var count: integer;
const array_size =25;
var YesOrNo: char;
Begin
count:=0;
FOR i:=0 TO 25 DO

begin

Writeln('Please enter Customer Name');
Readln(CustomerName[i]);
Writeln('Please enter ', CustomerName[i],' loan');
Readln(CustomerLoan[i]);
Writeln('Please enter ', CustomerName[i],' Salary');
Readln(CustomerSalary[i]);



Writeln('ALL CUSTOMERS');
FOR i:=0 TO count DO
begin
Writeln(CustomerName[i],'----Loan:',CustomerLoan[i],'-----Salary:',CustomerSalary[i]);
end;
Writeln('---------------------------------------------------');

Writeln('Customers with Loans equal to 1');
FOR i:=0 TO count DO
begin
if CustomerLoan[i]= 1 then begin
Writeln('Loan:',CustomerLoan[i],'---Name---',CustomerName[i],'-----Salary:',CustomerSalary[i]);
end;
end;
Writeln('---------------------------------------------------');


for i:=0 to count do begin

if CustomerSalary[i] &amp;gt; CustomerSalary[count] then begin

tmpCustomerName:= CustomerName[i];
tmpCustomerLoan:= CustomerLoan[i];
tmpCustomerSalary:= CustomerSalary[i];

CustomerName[i]:= CustomerName[count];
CustomerLoan[i]:= CustomerLoan[count];
CustomerSalary[i]:= CustomerSalary[count];

CustomerName[count]:= tmpCustomerName;
CustomerLoan[count]:= tmpCustomerLoan;
CustomerSalary[count]:= tmpCustomerSalary;

end;
end;
end;

Writeln('5 Customers with highest salaries');
FOR i:=0 TO 5 DO
begin
Writeln('Salary:',CustomerSalary[i],'---Name----',CustomerName[i],'----Loan:',CustomerLoan[i]);
end;
Writeln('---------------------------------------------------');



count :=count +1;
end;



end.


&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/412937/413063/re-arranging-sorting-an-array/#413063</guid>
      <pubDate>Thu, 04 Feb 2010 11:47:42 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: arranging sorting an array</title>
      <link>http://www.programmersheaven.com/mb/pasprog/412937/413064/re-arranging-sorting-an-array/#413064</link>
      <description>sorry for the double post</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/412937/413064/re-arranging-sorting-an-array/#413064</guid>
      <pubDate>Thu, 04 Feb 2010 11:50:47 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: arranging sorting an array</title>
      <link>http://www.programmersheaven.com/mb/pasprog/412937/413071/re-arranging-sorting-an-array/#413071</link>
      <description>: i have listed the entire code for reference at the bottom.&lt;br /&gt;
: &lt;br /&gt;
: however I have tried something similar to what you suggested&lt;br /&gt;
: I am still having the trouble of the sorting 'jumping ahead'.&lt;br /&gt;
&lt;br /&gt;
Your program has way too many errors to list, it doesn't even compile. Just adapt my code to your needs...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/412937/413071/re-arranging-sorting-an-array/#413071</guid>
      <pubDate>Thu, 04 Feb 2010 18:25:12 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: arranging sorting an array</title>
      <link>http://www.programmersheaven.com/mb/pasprog/412937/416646/re-arranging-sorting-an-array/#416646</link>
      <description>I use QuickSort to sort any array that needs&lt;br /&gt;
sorting and multiple arrays that either need&lt;br /&gt;
ascending or descending order.  I've made my&lt;br /&gt;
QuickSort into a unit.  Just follow what I've &lt;br /&gt;
done in my zip file with the example.&lt;br /&gt;
&lt;br&gt;&lt;br&gt;&lt;strong&gt;Attachment:&lt;/strong&gt; &lt;a href="http://www.programmersheaven.com/mb/DownloadAttachment.aspx?AttachmentID=1769"&gt;QuickSort.zip&lt;/a&gt; (43296 bytes | downloaded 224 times)</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/412937/416646/re-arranging-sorting-an-array/#416646</guid>
      <pubDate>Fri, 21 May 2010 20:17:30 -0700</pubDate>
      <category>Pascal</category>
    </item>
  </channel>
</rss>