Suggested Assignment

Consider the following list-structure for a book. Book might represent the current structure of a textbook. Suppose we want to print this information as a table of contents. It would appear as follows:

CHAPTER 1

1.1  ARRAYS

1.2  RECORDS

1.2.1 POINTERS

1.2.2 EXAMPLE

1.3  SUMMARY

CHAPTER 2

2.1  LISTS

2.2  USES

CHAPTER 3

3.1  APPLICATIONS

3.1.1  BACKGROUND

3.1.2  RANKINGS

3.1.2.1 FLOWCHART

This problem can be abstracted to the printing out of a "picture" of a list-structure. Assume all records are declared as

typedef struct listrecord

{

whatever info;

int recordtype;

struct listrecord *link,*sublist;

}bookrecord,*liststructurepointer;

Write a function printlist that will print out a "picture" of the list-structure pointed to by ls. Consider, for example, the list-structure accounts of Section 6.1. The list-structure is

INFO = 175

RECORDTYPE = COMPLEX

INFO   = 0

RECORDTYPE = COMPLEX

INFO   = 100

RECORDTYPE = SIMPLE

INFO  = 75

RECORDTYPE = SIMPLE

INFO  = 450

RECORDTYPE = COMPLEX

INFO   = 200

RECORDTYPE = COMPLEX

INFO   = 250

RECORDTYPE = SIMPLE

INFO  = -46

RECORDTYPE = SIMPLE

Your program should read in and echo print three list-structures. One should be null. It should then call on printlist to print out the "picture" for each of the three list-structures.

The input data for accounts might be

1     indicates a nonnull list-structure; 0 would indicate a null list

       structure

175  CMPLX

1    1   indicates the link and sublist fields of "175" are not null

0    CMPLX

1    1

100  SMPL

0     indicates the link field of "100" is null; it is thus the last record of

       a sublist

75   SMPL

0

450  CMPLX

1    1

200  CMPLX

1    0     indicates the link field of "200" is not null, but its sublist

            field is null

250  SMPL

0

-46  SMPL

0

Notice that the input is given in traversal order.

The printlist function is to have almost exactly the same detailed refinement as either the iterative traverse (Section 6.2.1 ) or the recursive traverse (Section 6.2.2). You must write the proper process routine, say process2, to turn traverse into printlist. You may add parameters to process2 if necessary.

For extra credit, do the reading in and echo printing of the three list-structures in the program by calling a function readechoprint. It must also be obtained by writing the proper process routine, say process1, to turn traverse into a function for readechoprint.

Of course, it will be necessary for you also to write the stack operation routines setstack, push, pop, and empty, as well as next, sublist, and complex.