pointlink.h
#ifndef _POINTLINK_H_
#define _POINTLINK_H_
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
typedef struct POINT{
int row;
int col;
struct POINT *next;
}POINT;
void initPointLink(POINT **h);
void showPoints(POINT *h);
void showPoint(POINT point);
void destoryPointLink(POINT **h);
#endif
pointlink.c
#include"pointlink.h"
void destoryPointLink(POINT **h){
POINT *p;
while(*h){
p = *h;
*h = p->next;
free(p);
}
}
void showPoint(POINT point){
printf("(%d, %d)\n",point.col,point.row);
}
void showPoints(POINT *h){
if(h){
for( ;h;h = h->next)
showPoint(*h);
}else{
printf("无数据");
}
}
void initPointLink(POINT **h){
POINT *p;
POINT *q;
int row;
int col;
if(*h){
printf("链表已经初始化,不能再次初始化");
}else{
printf("请输入坐标\n");
scanf("%d%d",&row,&col);
while(row && col){
p = (POINT *)malloc(sizeof(POINT));
p->row = row;
p->col = col;
p->next = NULL;
if(*h = NULL)
*h = p;
else
q->next = p;
q = p;
printf("请输入坐标\n");
scanf("%d%d",&row,&col);
}
}
}