单链表逆序



 // 1.单链表逆序//链表为带头结点的,head指向第一个结点typedef struct List{                       int data;                       List * next;                     }NodeList; NodeList * Reverse(NodeList * head){        if (!head || !head->next)              return head;               NodeList *p1 = head;        NodeList *p2 = head->next;        head->next = NULL;        while(p2)         {                p1= p2;                p2 = p2->next;                p1->next = head;                head=p1;         }                return head;}// 2.下面的例子为 “单链表逆序输出”void printList (NodeList *head){       if (head == NULL)           return;              if (head->next == NULL)         printf("%d", head->data);      else        {             printList (head->next);             printf("%d", head->data);         }}
阅读更多
文章标签: null list struct
个人分类: Interview Question
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭