Solved

sorting lines in pascal

Posted on 1998-09-01
5
312 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Client Data Set - Wide Memo 6 1,731
Get notified when a TPopupMenu closes? 4 171
delphi custom sort exception 6 136
delphi prevent click fast 2 191
What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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