Merge sort without linear / linked lists / pointers?

  • Follow


Hi!

Is it possible to implement a merge-sort in Pascal without having 
dynamic arrays and without having to use pointers (Linked lists / linear 
lists)?
Google only brought up results using pointers...

Thank you!

regards,
    Chriss
0
Reply Christian 4/22/2004 4:11:50 PM

On Thu, 22 Apr 2004 18:11:50 +0200, Christian Muenscher <crion@gmx.de>
wrote:

>Is it possible to implement a merge-sort in Pascal without having 
>dynamic arrays and without having to use pointers (Linked lists / linear 
>lists)?
>Google only brought up results using pointers...

Yes, if you can make static arrays large enough for the data.

---
Replace you know what by j to email
0
Reply Jud 4/22/2004 5:00:30 PM


On 2004-04-22, Christian Muenscher <crion@gmx.de> wrote:
> Hi!
>
> Is it possible to implement a merge-sort in Pascal without having 
> dynamic arrays and without having to use pointers (Linked lists / linear 
> lists)?
> Google only brought up results using pointers...

Only if the number of files is limited.

Without dynamic mem there is no way to keep track of a variable number of
files.

It also depends on what you call merge sort. Is it only the last stage, or 
does it involve the creation of the sorted beginfiles also?
0
Reply Marco 4/22/2004 8:28:34 PM

"Christian Muenscher" <crion@gmx.de> wrote in message news:c68qri$9cchh$1@ID-5299.news.uni-berlin.de...
> Hi!
>
> Is it possible to implement a merge-sort in Pascal without having
> dynamic arrays and without having to use pointers (Linked lists / linear
> lists)?
> Google only brought up results using pointers...
>
> Thank you!
>
> regards,
>     Chriss

Whats wrong with pointers ?

Anyways, no, ISO 7185 Pascal (the original Pascal) would need
either an array larger than the anticipated data, or pointers.
That (pointers) can be made much more space efficent by allocating
data in "chunks" of 100 or so data items, instead of one data, one
pointer.

In any case, variable length arrays is a common Pascal extention.
Your compiler may offer such a feature.


0
Reply Scott 4/23/2004 8:09:24 AM

Scott Moore wrote:
> "Christian Muenscher" <crion@gmx.de> wrote in message
>>
>> Is it possible to implement a merge-sort in Pascal without
>> having dynamic arrays and without having to use pointers (Linked
>> lists / linear lists)?
>> Google only brought up results using pointers...
> 
> Whats wrong with pointers ?
> 
> Anyways, no, ISO 7185 Pascal (the original Pascal) would need
> either an array larger than the anticipated data, or pointers.
> That (pointers) can be made much more space efficent by allocating
> data in "chunks" of 100 or so data items, instead of one data, one
> pointer.
> 
> In any case, variable length arrays is a common Pascal extention.
> Your compiler may offer such a feature.

There are various flavors of merge sorts.  One operates in memory,
preferably on linked lists (which in turn can be implemented in
arrays).  Another merges external files, and is basically
unlimited as to final file size.  One extreme of this is
poly-phase sort.

-- 
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!


0
Reply CBFalconer 4/23/2004 9:53:41 AM

I was about to say that myself!  About 15 years ago, I wrote a very
primitive spell-checker (hmm -- maybe 20 years ago!) that broke a
manuscript apart into words, sorted the words, then compared them with
a (sorted) dictionary.  As I was using a PDP-11 with (I think) at most
2M memory (my memory is starting to go here), I definitely needed an
"external sort" and coded a version of polyphase merge sort, following
the example in Wirth's book "Algorithms + Data Structures = Programs".
Definitely "vanilla Pascal", no dynamic arrays, and no pointers in
this particular program.

Bob Schor
Pascal Enthusiast

On Fri, 23 Apr 2004 09:53:41 GMT, CBFalconer <cbfalconer@yahoo.com>
wrote:

>Scott Moore wrote:
>> "Christian Muenscher" <crion@gmx.de> wrote in message
>>>
>>> Is it possible to implement a merge-sort in Pascal without
>>> having dynamic arrays and without having to use pointers (Linked
>>> lists / linear lists)?
>>> Google only brought up results using pointers...
>> 
>> Whats wrong with pointers ?
>> 
>> Anyways, no, ISO 7185 Pascal (the original Pascal) would need
>> either an array larger than the anticipated data, or pointers.
>> That (pointers) can be made much more space efficent by allocating
>> data in "chunks" of 100 or so data items, instead of one data, one
>> pointer.
>> 
>> In any case, variable length arrays is a common Pascal extention.
>> Your compiler may offer such a feature.
>
>There are various flavors of merge sorts.  One operates in memory,
>preferably on linked lists (which in turn can be implemented in
>arrays).  Another merges external files, and is basically
>unlimited as to final file size.  One extreme of this is
>poly-phase sort.

0
Reply Bob 4/28/2004 3:26:58 AM

5 Replies
437 Views

(page loaded in 0.075 seconds)

Similiar Articles:










7/29/2012 8:32:35 AM


Reply: