Solved

sorting lines in pascal

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Delphi & Indy 10 Whois over Web Proxy 3 1,223
Utf8 encode 2 595
How do I assign an IP address to my Delphi Datasnap server? 4 823
.dat problems 39 211
While it may be true that the internet is a place of possibilities, it is also a hostile environment lurking with many dangers. By clicking on the wrong link, trusting the wrong person or using a weak password, you are virtually inviting hackers to …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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