RPG Next Gen
Wiki RSS Feed Bug Reporting Weblog
Business picture

Linked List

Linked lists and arrays are similar since they both store collections of data. The terminology is that arrays and linked lists store "elements" on behalf of "client" code.

An array allocates memory for all its elements lumped together as one block of memory. In contrast, a linked list allocates space for each element separately in its own block of memory called a linked list element or node . The list gets is overall structure by using pointers to connect all its nodes together like the links in a chain.

A more sophisticated kind of linked list is a doubly-linked list or two-way linked list. Each node has two links: one points to the previous node, or points to a null value or empty list if it is the first node; and one points to the next, or points to a null value or empty list if it is the final node.

For a more detailed description see Wikipedia: Linked List or the Stanford CS education library.

Features

The following features are available in the linked list service program (in no particular order):

  • Creating a linked list
  • Adding to the linked list (beginning, end, by index)
  • Adding all entries of another list
  • Replaceing entries of the list
  • Removing entries from the list (beginning, end, by index)
  • Creating a sublist
  • Rotating the list
  • Clear the list
  • Check size of the list
  • Check fill status of list (empty or not empty)
  • Get entry of the list (beginning, end, by index)
  • Check if the list contains an item
  • Iterate through the list (forward and backward)
  • Get index of an entry
  • Get last index of an entry
  • Copy all entries to a character array
  • Swap entries in the list
  • Execute a procedure on all entries of the list
  • Reverse list
  • Create a list from a character string
  • Create a copy of a list
  • Count the frequency of an entry in the list
  • Data type specific procedures for storing and getting values
  • Sort list
  • Merge two lists

The following features may find it into the next release:

  • move — move an entry up or down the list n positions
  • shuffle — shuffle the list into random order

Implementation

The implemented list is a doubly-linked list. Entries are stored in dynamically allocated memory (allocated via %alloc). Because of that it is necessary to use the dispose procedure after using the list for freeing up the allocated memory. If the memory is not freed with the dispose procedure it will be released with the ending of the activation group or job.

The code is written in RPG IV free format. It uses some C-functions for working with memory and strings and intensely uses pointers.

Code sample

// creating a list listPtr = list_create(); // check if the list is empty (it should be) if (list_isEmpty(listPtr)); dsply 'List is empty'; else; dsply 'List is not empty'; endif; // create a new list which is populated with // a subset of data from the original list sublistPtr = list_sublist(listPtr : 2); // iterate through the entries of the list valuePtr = list_getNext(sublistPtr); dow (valuePtr <> *null); value = %str(valuePtr); dsply value; valuePtr = list_getNext(sublistPtr); enddo; // freeing the allocated memory list_dispose(listPtr);

Examples

The examples section contains some examples of how to use the linked list.

Download

For source and binary packages take a look at the download area.

Documentation

API documentation of the Linked List service program can be downloaded in HTML format or viewed at the ILEDocs Sourceforge.net project. The documentation is generated from the source code.


Donations

Collab Sites

Dieter Bender DV
Thomas Raddatz
ILEDocs
iDevCloud
YiPs

Projects


rss feed Latest News

  • 2012-10-05 - JT400 Javadocs
  • 2012-08-24 - JSON service program release 1.4.5
  • 2012-07-28 - JSON service program release 1.4.4
  • 2012-07-24 - JSON service program release 1.4.3
  • 2012-02-10 - missing RUNUNITEST program uploaded
  • 2011-10-23 - JSON service program release 1.4.2
  • 2011-09-13 - JSON service program release 1.4.1
  • 2011-08-27 - New Modular project
  • 2011-07-24 - JSON service program release 1.4.0
  • 2011-06-05 - New Stomp Client project and release 1.0.0
  • 2011-06-05 - Includes update to 1.2.0
  • 2011-05-09 - zlib port for IBM i
  • 2011-05-09 - New Properties project and release 1.0.0
  • 2011-05-03 - Includes updates
  • 2011-05-03 - libtree release 1.1.0
  • 2011-04-30 - JSON service program release 1.3.1
  • 2011-04-29 - Vector changed to ArrayList with a new release
  • 2011-02-23 - Linked List service program release 1.3.0
  • 2011-02-18 - Red Black Tree implementation docs
  • 2011-02-14 - JSON service program release 1.3.0
  • 2011-02-13 - RNG Input Provider release 1.1.1
  • 2011-02-11 - libtree release 1.0.0
  • 2011-02-05 - New Validator Service Program available
  • 2011-01-30 - New Flat File Parser project
  • 2011-01-15 - RNG Input Provider example added
  • 2011-01-10 - RNG Input Provider release 1.1.0
  • 2011-01-08 - RPG Next Gen Editor update site updated
  • 2011-01-03 - CCSID conversion script updated
  • 2010-12-30 - New project Input Providers
  • 2010-12-27 - CCSID conversion script in section resources
  • 2010-12-12 - RPG Next Gen Editor release 0.5.5
  • 2010-12-12 - RPG Unit Test release
  • 2010-10-02 - New project Unit Testing for RPG

Last updated

2012-10-05