码迷,mamicode.com
首页 > 其他好文 > 详细

C,单链表翻转函数

时间:2018-04-21 00:23:25      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:链表   反转   

struct ST_StackNode
{
int num;
datatype data;
struct ST_StackNode *pNext; //指针域
};
typedef struct ST_StackNode StackNode;

StackNode reverse(StackNode phead)
{
if (phead == NULL){ return NULL; }
if (phead->pNext == NULL) { return phead; }

StackNode* pre, *cur, *next;

cur = phead->pNext;
phead->pNext = NULL;
pre = phead;

while (cur != NULL)
{
    next = cur->pNext;
    cur->pNext = pre;
    pre = cur;
    cur = next;
}
phead = pre;
return phead;

}

C,单链表翻转函数

标签:链表   反转   

原文地址:http://blog.51cto.com/12211918/2105941

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!