Solved

sorting lines in pascal

Posted on 1998-09-01
5
311 Views
Last Modified: 2008-02-26
my goal is to read from an input file and sort the lines(up to 500) alphbetically and then print the sorted list.  I am not using turbo pascal just pascal.  What is the best way to store and sort these lines of up to 80 characters?
0
Comment
Question by:csturner
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
Nuno Alves earned 100 total points
ID: 1215490
Hello.
You should use the quicksort algorithm or bubblesort algorithm. The quicksort algorithm is faster than the bubblesort but bubblesort is easier to implement. But if you have a lot of data to sort it's better to use quicksort.
I think that turbo pascal have the code for the quicksort algorithm, search on help.
Regards.
0
 

Author Comment

by:csturner
ID: 1215491
I would still like to know HOW TO STORE THE LINES BY LINE IN ORDER TO SORT THEM BY LINE.  EX. NAMES IN THE TELEPHONE BOOK == GIVEN A LIST OF NAMES SORT THEM === How do I read them in and store them in order to do the sort.
0
 
LVL 1

Expert Comment

by:Nuno Alves
ID: 1215492
Please be more specific.
I didn't understand what do you mean with "STORE THE LINES BY LINE IN ORDER TO SORT THEM BY LINE".
Do you want to know the specific algorithm to compare the lines to sort? that's it?
0
 

Author Comment

by:csturner
ID: 1215493
Ok.  This is my first pascal program so sorry if I sound cofusing: ) What I need to do is tale a text file and put lines in ascending order.  ex. The dog ran fast.
                         The cat meowed.
                         The man walked.

I f this is in my text file , I need to read it in sort it and print out:   The cat meowed.
             The dog ran fast.
             The man walked.

I am having trouble not in the area of sorting but in how to accomplish keeping up with the lines as I go.  I am not using Turbo Pascal which allows for strings or whatever.  I do not know how to store the lines in order to print them at a later time.
Something like an array of arrays or something?? I am not sure how to go about this.  If I can get the lines stored somewhere, I believe I can sort them ok.  I just can't get beyond that point.
Does pascal allow an easier way?  Like I said I am not to familar with the language.  Thank You for your help.
0
 
LVL 1

Expert Comment

by:Nuno Alves
ID: 1215494
If you are using standart pascal you can use the following structure:

type
     string = packed array [1..80] of char;
var
     lines: array [1..500] of string;

I think that is what you want.
Regards
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now