🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #1860

Re: POINTER/LINKED LIST HELP?

#1860
From: Gerhard Moeller
Date: Sun, 31 Mar 1991 17:50
78 lines
3850 bytes
Hi.
2hnenature@kuhub.cc.ukans.edu writes:


>  I seem to have a problem with using the type POINTER with linked lists.
>I have a seperate module with linked list functions such as Delete,Insert,
>NewList etc., that I have written myself.  The problem is that I wish to make
>these procedures as general as possible so they can be used with a variety of
>programs.  Is it possible to specify a general POINTER type that can point to
>any data type?  I assume it must be possible since the function NEW(x) allows x
>to be a pointer to any type of data. 
Yes, as far as I know, use ADDRESS. (Must be imported from SYSTEM) Then
you can do something like this:

PROCEDURE InsertElement (Root		:ADDRESS;
			 Element	:ADDRESS)	: BOOLEAN;

Now it doesn't care of what Element the Pointer points. But however yet
be warned: The internal Structure of the Elements should be at least
similar, I don't want to know what happens if you try to insert a
FIFO-List-Element into a Bayer-Tree...

> Related to this, I have a field in my linked list of RECORDS that contains a 
>pointer to the next element in the linked list. The field is presently called
>Link and I use this field to traverse the list:
> 
>eg.  WHILE Current#NIL DO
>            Current:=Current^.Link...

>As it stands now any linked list that wants to use these functions must have
>a field called "Link."  
What I said above. ;-)

>Is there any way I could remove this limitation?  It is
>handicapping, since if I want to use two different linked lists in a program I
>must have a field "Link" in each list.
Tricky. (As I'm not a Modula-Guru, I really have to think now for a
while. Imagine me walking all around the room and drinking coffee...)
Well, I would assume the following:
Create an opake Type ElementLink that contains a variant Record for e.g.
single lists, double, Trees, B-Trees, and whatever you like. Any Element
you create has now a field "next : ElementLink". But, of course, now you
can only use your own routines for accessing, creating, deleting and so
on. I hope you got me?

{ TYPE tLinkTypes	: (List, DoubleList, Tree, BTree, TwoThreeTree, ...)
  TYPE tElementLink	: RECORD
			    CASE LinkType OF tLinkType
				(* sorry, I forgot the syntax for
				variant records. Please have a look by
				your own. (It's a long time ago, I
				programmed in Modula...) *)
			    | List	: next :ADDRESS;
			    | DoubleList: next, prev :ADDRESS;
				.
				.
				.
}
>Am I making any sense?
Well, I don't even know if I was making sense, so how could I know about
you? 

>  BTW I am using a VMS Modula-2 compiler. 
>                                 Thanks for any help...
>                                        S Pendleton
I don't know that one, if it's standard, no problems...
(Except if I was tellin' bull.)

Ciao, Yours Gerhard.
("Never trust a hippy"... - Sex Pistols)
-- 

+---------------------------< principiis obsta! >---------------------------+
| Gerhard Moeller, Teichstrasse 12, 2900 Oldenburg (FRG)    [Geb. 02/21/68] |
|    inhouse: gimli!gemoe               uucp: ...(unido!)uniol!gmoeller     |
|DOMAIN: gerhard.moeller@arbi.informatik.uni-oldenburg.de                   |
|BITNET: gmoeller%arbi.informatik.uni-oldenburg.de@DOLUNI1 (106495@DOLUNI1) |
+-----------------------> the medium is the message <-----------------------+
Technical Details
Message-ID: <5164@uniol.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!uunet!mcsun!unido!uniol!Gerhard.Moeller
References: <1991Mar30.151406.29367@kuhub.cc.ukans.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!uunet!mcsun!unido!uniol!Gerhard.Moeller
From: Gerhard.Moeller@arbi.informatik.uni-oldenburg.de (Gerhard Moeller)
Newsgroups: comp.lang.modula2
Subject: Re: POINTER/LINKED LIST HELP?
Message-ID: <5164@uniol.UUCP>
Date: 31 Mar 91 17:50:41 GMT
References: <1991Mar30.151406.29367@kuhub.cc.ukans.edu>
Organization: University of Oldenburg, Germany
Lines: 78