การประกาศต่อไปนี้ จะใช้สำหรับการเขียนฟังก์ชันและฟังก์ชั่นในตัวอย่าง 1
#define STRING30 30
typedef struct ptr
{
int id ;
char name [STRING30] ;
float score ;
struct ptr *link ;
} Ptr ;
ตัวอย่าง 1 การเขียนฟังก์ชันชื่อ appendList เพื่อทำการเชื่อมโยงลิสต์ 2 ชุดเข้าด้วยกันเป็นลิสต์เดียว ดังภาพตัวอย่างต่อไปนี้
ภาพก่อนการเชื่อม
8 1108
head1 head2
8 1108
ภาพภายหลังการเชื่อมต่อเรียบร้อยแล้ว
head1
head2
void appendList (ptr **head, ptr **head2)
{
Ptr *start ;
If (*head1 = = NULL)
*head1 = *head2 ;
else
{
start = *head1;
while (start -> link ! = NULL )
start = start -> lunk ;
start -> link = *head 2 ;
}
} /* appendList */