From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c968fe4b2cbebf4 X-Google-Attributes: gid103376,public From: Alfred Hilscher Subject: Sort, was Re: HELP WITH SIMPLE PROGRAM PLEASE Date: 2000/04/18 Message-ID: <38FC0D8C.2F734149@icn.siemens.de>#1/1 X-Deja-AN: 612580613 Content-Transfer-Encoding: 7bit References: <8df1sn$hh4$1@nnrp1.deja.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Siemens AG Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-04-18T00:00:00+00:00 List-Id: ashraf2000@x-stream.co.uk wrote: > > HI, > > I am a beginner and trying to sort numbers which are read from a file > in random order and needs to be sorted out in numerical order. > e.g 7,10,1,5,.... into 1,2,3,.... > Below is some code to read the number from a file and display them. > > Please help me sort them out. > begin > read; > check; > output; Ok. What you have is quite good. You read the data and you write them. The remaining part is to sort them. Your procedure check is a good starting point. You check two number and if they are in the wrong order you swap them. So do this not only for no(1) and no(2) but do it for all numbers until they are ascending. For more information on sorting algorithms you should look into the literature, e.g. Wirth's "Algorithm and datastructures".