热门IT资讯网

C,单链表翻转函数

发表于:2024-11-24 作者:热门IT资讯网编辑
编辑最后更新 2024年11月24日,struct ST_StackNode{ int num; datatype data; struct ST_StackNode *pNext; //指针域};typedef s
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;}
0