首页 >

带有一个头结点的单链表l为空的条件是 一个带头结点的单链表


来源: 城市网


(相关资料图)

1、typedef struct ListNode{ListNode *next;Element data;}ListNode, *pList;这是我做的单链表逆序三个不同的算法。

2、2个递归的以及一个非递归的pList ReverseList( pList head ){if( !head || !(head->next) )return head;pList ph = ReverseList( head->next );head->next->next = head;head->next = NULL;return ph;}pList ReverseList( pList head , pList &tail ){if( !head || !(head->next) ){tail = head;return head;}pList pt;pList ph = ReverseList( head->next , pt );pt->next = head;head->next = NULL;tail = head;return ph;}pList ReverseListNonRec( pList head ){if( !head || !(head->next) )return head;pList h = NULL,h1 = head;while( head ){h1 = head->next;head->next = h;h = head;head = h1;}return h;}。

相信通过一个带头结点的单链表这篇文章能帮到你,在和好朋友分享的时候,也欢迎感兴趣小伙伴们一起来探讨。

本文由用户上传,如有侵权请联系删除!

[责任编辑:cqsh]