1 2 3 4 5 6 7 8 9

#define Nodeptr struct node*//prefertypedef
See King P. 335 or K&R Section 6.7 (typedef):
create data type names


typedefstruct node* Nodeptr;

typedefstruct node {
int data;
Nodeptr next;
}
Node;

// struct node* next;

Nodeptr mknode (int value)
{
Nodeptr np;
//np = (Nodeptr) malloc (sizeof (Node));
np = (Nodeptr) malloc (sizeof (struct node));
if (np != NULL) {
np->data = value;
np->next = NULL;
}
return np;
}


Sometimes we want one field in a data structure to hold
two values of different type. Say for instance either an
integer or a float. We can do this through the use of a
union--forming something much like a variant record in
Pascal.

February 15 1998

Page 1

TAM C201 notes