basic operations on liststructure

liststructurepointer next(p)

/* Returns a copy of the link field

value of record pointed to by p.

*/

liststructurepointer p;

{

return(p->link);

}

liststructurepointer sublist(p)

/* Returns a copy of the sublistpointer

field value of record pointed to by p.

*/

liststructurepointer p;

{

return(p->sublistptr);

}

liststructurepointer setnull()

/* Returns a null pointer */

{

return(NULL);

}

liststructurepointer avail()

/* Returns a pointer to storage allocated

for a liststructure record of type

examplerecord.

*/

{

return(malloc(sizeof(examplerecord)));

}

complex(p)

/* Returns true only if the record pointed

to by p is complex.

*/

liststructurepointer p;

{

return(p->kind == 1);

}

createrecord(l,ptr)

/* Reads in the data for the current record

and sets its fields appropriately.

*/

liststructurepointer 1,ptr;

{

int link,subptr,value,kind;

liststructurepointer setnull(),avail();

printf("\n enter info \n");

scanf("%d",&value);

printf("\n enter 0 for simple 1

for complex \n");

scanf("%d",&kind);

if (kind == 0)

{

printf("\n enter link \n");

scanf("%d",&link);

if (link == 0)

ptr->link = setnull();

else

ptr->link = avail();

}

else

{

printf("\n enter link & subptr \n");

scanf("%d %d",&link,&subptr);

if (link == 0)

ptr->link = setnull();

else

ptr->link = avail();

if (subptr == 0)

ptr->sublistptr = setnull();

else

ptr->sublistptr = avail(); 

}

ptr->info = value;

ptr->kind = kind:

}

printrecord(pls,ptr)

/* Prints the contents of the info field

of the record pointed to by ptr.

*/

liststructurepointer *pls,ptr;

{

printf("\n %d \n",ptr->info);

}