c primer上的链表例子
数据类型定义
struct film
{
char title[TSIZE] ;
int rating ;
} ;
typedef struct film Item ;
typedef struct node
{
Item item ;
struct node *next ;
} Node ;
typedef Node * List ;
List movies ;
void InitializeList(List *plist)
{
*plist = NULL ;
}
typedef struct node
{
int item ;
struct node *next ;
} Node ;
typedef struct queue
{
Node * front ;
Node * rear ;
int items ;
} Queue ;
Queue line ;
void InitializeQueue(Queue *pq)
{
pq->front = pq->rear = NULL ;
pq->items = 0 ;
}
typedef int datatype;
typedef struct node
{
datatype data;
struct node *next;
}node,*link;
typedef struct queue
{
link front;
link rear;
}queue,*queue_link;
void queue_init(queue_link *Q)
{
link p;
*Q = (queue_link)malloc(sizeof(queue));
if(NULL == *Q)
{
perror("malloc");
exit(-1);
}
p = (link)malloc(sizeof(node));
if(NULL == p)
{
perror("malloc");
exit(-1);
}
p->next = NULL;
(*Q)->front = (*Q)->rear = p;
}