?
Solved

sorting lines in pascal

Posted on 1998-09-01
5
Medium Priority
?
320 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
Nuno Alves earned 400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Summer 2017 Scholarship Winners have been announced!
Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 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