首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

关于一个已排序成功的链表的内容处理有关问题

2012-04-07 
关于一个已排序成功的链表的内容处理问题C/C++ code//多项式指数排序void Rank (Count * pHead){struct Co

关于一个已排序成功的链表的内容处理问题

C/C++ code
//多项式指数排序void Rank (Count * pHead){    struct Count * p = pHead->pNext;    struct Count * temp;    while (p != NULL)    {        while (p->pNext != NULL)        {            if (pHead->pNext->Last > p->pNext->Last)            {                temp = pHead->pNext;                pHead->pNext = p->pNext;                p->pNext = pHead->pNext->pNext;                pHead->pNext->pNext = temp;            }            else                p = p->pNext;        }        pHead = pHead->pNext;        p = pHead->pNext;    }    return;}


以下函数目的为了将一个按多项式(已按指数大小排好序)合并同类项。last为指数,val为系数。
编译是通过了,运行到这函数是就出错了,求指导。谢谢!
C/C++ code
void Handle (Count * pHead){    struct Count * p_First = pHead->pNext;    struct Count * p_After = pHead->pNext->pNext;    while (p_First != NULL)    {        if (p_First->Last == p_After->Last)        {            p_First->Val += p_After->Val;            p_First->pNext = p_After->pNext;            p_After = p_After->pNext;        }        else        {        p_First = p_First->pNext;        p_After = p_After->pNext;        }    }    return;}


[解决办法]
while (p_First != NULL)这里应该判断的是p_After != NULL
[解决办法]
C/C++ code
while (p_First != NULL && p_After != NULL)//这里要一起判断,不然里边用到p_After会出错 

热点排行