编程实现一个单链表的打印

xiaoxiao2021-02-28  91

【单链表的打印】:

//单链表的打印 void print(node *head) { node *p; int index = 0; if(head->next == NULL) //链表为空 { cout << "Link is empty"<<endl; return; } p = head->next; while(p != NULL) { cout<<"The "<<++index << "node is :"<< p->data <<endl; //打印元素 p = p->next; } }

转载请注明原文地址: https://www.6miu.com/read-66466.html

最新回复(0)