在链接列表交换期间未传递指针

Pointer is not being passed during a linked list swap

这很可能看起来像是我遗漏了一些明显的东西,但是当我尝试将链接列表指针传递给我的选择排序时,我遇到了 NULL 指针问题。在我的 C 代码中,我将其作为链接列表:

typedef struct iorb
{
    int base_pri;
    struct iorb *link;
    char filler[100];
} IORB;

然后我在创建后将我的新链表传递给这个函数:

void swapNodes(POINTER *head, POINTER CurrentHead, POINTER CurrentMinimum, POINTER TempSwap);

POINTER SortList(POINTER *head, char *SortMethod[])
{
    POINTER TempHead = *head;

    //Only one node, no need to sort.
    if (TempHead->link == NULL)
    {
        return head;
    }

    //Store node with the new minimum value.
    POINTER TempMin = *head;

    //Store curent node for swapping
    POINTER TempSwap = *head;

    //Transverse the list.
    POINTER TempCurrent;
    for (TempCurrent = *head; TempCurrent->link != NULL; TempCurrent = TempCurrent->link)
    {
        //Check if this node has a lower priority than the current minimum and if so, swap them.
        if (TempCurrent->link->base_pri < TempMin->base_pri)
        {
            TempMin = TempCurrent->link;
            TempSwap = TempCurrent;
        }
    }

    //Swap nodes if the head is not the same as the minimum.
    if (TempMin != TempHead)
    {
        swapNodes(&TempHead, TempHead, TempMin, TempSwap);
    }   

    //Recursively sort the rest of the list.

    //FOR SOME REASON THE NODE POINTER IS NOT BEING PASSED HERE (EMPTY)
    TempHead->link = SortList(TempHead->link, *SortMethod);

    return head;

}

void swapNodes(POINTER *head, POINTER CurrentHead, POINTER CurrentMinimum, POINTER TempSwap)
{
    //Set new head as the minimum.
    *head = CurrentMinimum;

    //Link the current temp swap to the head.
    TempSwap->link = CurrentHead;

    //Swap pointers.
    POINTER temp = CurrentMinimum->link;
    CurrentMinimum->link = CurrentHead->link;
    CurrentHead->link = temp;
}

我不确定为什么它没有传回同一个函数,当我调试链表时似乎没问题。我怀疑我在交换节点函数中遗漏了一些东西,但我不太明白这是什么。有人可以提供一些关于这段代码应该如何交换节点的见解吗?

如果您需要更多信息,请告诉我。

SortList(TempHead->link, *SortMethod);需要列为 SortList(&TempHead, *SortMethod);

要正确传递指针。