/*打印单链表*/
void print(node *head)
{
node *p; /*新定义一个节点指针*/
int index = 0; /*记录元素号*/
if(head->next == NULL) /*链表为空*/
{
printf("Link is empty!\n");
return ;
}
p = head->next; /*节点指针指向下一个节点*/
while(p != NULL) /*遍历链表*/
{
printf("The %dth node is:%d\n" , ++index , p->data);/*打印元素*/
p = p->next;
}
}
/*单链表的打印与单链表的测长方法类似,使用while循环
进行遍历链表所有节点并打印各个节点内容,当遇NULL结束*/
void print(node *head)
{
node *p; /*新定义一个节点指针*/
int index = 0; /*记录元素号*/
if(head->next == NULL) /*链表为空*/
{
printf("Link is empty!\n");
return ;
}
p = head->next; /*节点指针指向下一个节点*/
while(p != NULL) /*遍历链表*/
{
printf("The %dth node is:%d\n" , ++index , p->data);/*打印元素*/
p = p->next;
}
}
/*单链表的打印与单链表的测长方法类似,使用while循环
进行遍历链表所有节点并打印各个节点内容,当遇NULL结束*/