🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #1864

Re: POINTER/LINKED LIST HELP?

#1864
From: 2hnenature
Date: Mon, 01 Apr 1991 18:38
73 lines
3869 bytes
In article <5164@uniol.UUCP>, Gerhard.Moeller@arbi.informatik.uni-oldenburg.de (Gerhard Moeller) writes:
> 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...

  OK, that makes sense, but when I try to implement it and try to access a field
of the record that for example "Root" is pointing to I get an error:

           Current:=Root^.Link
                          ^ Is not a field of a record (something like that)
           
and that makes sense too since the compiler sees "Root" as an ADDRESS type and
not as a pointer to a record. Thus the fields are not recognized, (I guess).
Also DISPOSE and NEW do not let me send an ADDRESS type as a parameter.
 Furthermore (as if you guys have nothing better to do than help me) another
error I get is:
        
          Current:=Root^.Link
          ^ Incompatible type (?)

  I get this error because the field "Link" is a pointer to a record and not an
ADDRESS type.

     Is there any way around this or should I give up? Does anybody know where
I could get some source code for linked list functions that are already
written?
   Thanks for help recieved.

> 
>> 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.
>>                                 Thanks for any help...
>>                                     S Pendleton 
> 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: <1991Apr1.123810.29390@kuhub.cc.ukans.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!kuhub.cc.ukans.edu!2hnenature
References: <1991Mar30.151406.29367@kuhub.cc.ukans.edu> <5164@uniol.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!kuhub.cc.ukans.edu!2hnenature
From: 2hnenature@kuhub.cc.ukans.edu
Newsgroups: comp.lang.modula2
Subject: Re: POINTER/LINKED LIST HELP?
Message-ID: <1991Apr1.123810.29390@kuhub.cc.ukans.edu>
Date: 1 Apr 91 12:38:10 CST
References: <1991Mar30.151406.29367@kuhub.cc.ukans.edu> <5164@uniol.UUCP>
Organization: University of Kansas Academic Computing Services
Lines: 73