× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



My first question would be "do you really need a linked list?"  You might
want to think about dynamically resizing an array.  If you need to search or
sort, a linked list may not be the easiest thing to work with, especially
given what rpg will do for you in arrays.  The rpg redbook has a nice
example of array resizing.

Here's a simple program that creates a ten element singly linked list and
traverses it.  In real life you'd want to encapsulate the various functions
of the list--create, add, delete, traverse, etc. rather than do them in
in-line code.  I'll bet there's a more elegant way to do this--it's been a
few years since I've used a linked list.  Note that the next pointer in the
previous element is assigned the address of the new element when an element
is added.

     H  dftactgrp(*no) actgrp(*caller)
     H OPTION( *SrcStmt: *NoDebugIO)
     Dlink             ds                  based(curr )
     Ddata                            5p 0
     Dnext                             *
     D
     D first           s               *
     D
     D sizeoflink      s              5u 0 inz(%size(link))
     D curr            s               *
     D x               s              5u 0
     c*  Create the list
     C                   alloc     sizeoflink    first
     C                   eval      curr = first
     C                   eval      data = 1
     C
     C* add 9 more elements
     C                   for       x = 2 to 10
     C                   alloc     sizeoflink    next
     C                   eval      curr = next
     C                   eval      data = x
     C                   eval      next = *null

     C                   endfor
     C
     C* traverse the list
     C                   eval      curr = first
     C                   dow       next <> *null
     C                   eval      curr = next
     C                   enddo
     C                   eval      *inlr = *on

> -----Original Message-----
> From: SCarter@rsrcorp.com [mailto:SCarter@rsrcorp.com]
> Sent: Tuesday, January 08, 2002 12:04 PM
> To: rpg400-l@midrange.com
> Subject: Help a pointer Newbie out...
>
>
> I searched the archives and the FAQ for information on using
> pointers to
> linked lists
> and I did not find anything useful to ME...
> that having been said can some one give me an example of
> using pointers for
> linked lists
> I have the classic list problem I know what type of data I
> need but i don't
> know how much.
> I could write the data out to a file in QTEMP and just
> process the file but
> I did not want to do
> that unless I can't wrap my brain around this pointer thing
> in a reasonable
> amount of time.


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.