this portion of the program is independent of the list implementation

#include <stdio.h>

#define TRUE 1

#define FALSE 0

main()

/* Inputs a series of stockrecords,

creates a list of the records, and

prints the contents of each list

record's infofield

*/

{

listpointer stocks,recordpointer,next();

int done;

initialize(&stocks);

recordpointer = stocks;

done = FALSE;

while(!done&&anotherrecord(recordpointer))

{

addrecord(&stocks,recordpointer,&done);

recordpointer = next(recordpointer);

}

recordpointer=stocks;

while (anotherrecord(recordpointer))

{

printrecord(recordpointer);

recordpointer = next(recordpointer);

}

}

initialize(plistname)

/* Allocates storage for the first record

and sets listname to point to it

*/

listpointer *plistname;

{

listpointer avail();

*plistname = avail();

}

addrecord(plistname,recordpointer,pdone)

/* Fills in the current record's data, and

allocates storage for the next record and

adds it to the list. If there is no data for

the current record it sets the link field of

the last list record to null, or the list

head, to null, and done to true.

*/

listpointer *plistname,recordpointer;

int *pdone;

{

static listpointer predecessor;

listpointer setnull(),avail(),

getnextrecord(),pointer;

pointer = getnextrecord();

if (pointer != setnull())

{

setinfo(recordpointer,pointer);

setlink(recordpointer,avail());

predecessor = recordpointer;

}

else if (*plistname != recordpointer)

{

setlink(predecessor,setnull());

*pdone = TRUE;

}

else

{

*plistname = setnull();

*pdone = TRUE;

}