带有节点的C ++非法间接

时间:2014-11-28 02:43:38

标签: c++ sorting queue nodes bubble-sort

我一直试图找到一种方法来根据他们的“优先级”值/变量对我的节点(双重链接)进行排序。然而,我一直陷入“非法间接”错误,并且不确定它意味着什么(尽管环顾四周)。

任何帮助都会非常感激,这里是代码,它是从另一个类似于我在stackOverflow上的回答问题中获取的,所以它可能被错误地实现,但我提供了部分Node类,以及使用排序功能(在“队列类”中);

我在“排序功能”块中突出显示了错误(很好地指出),感谢任何帮助。

NODE CLASS

class Node
{
public:
Node *next;         //Pointer to the next node
Node *prev;         //Pointer to the previous node
Node(N i, int s, Node *nextptr, Node *prevptr = NULL, int currentPriority = 0, int currentId = 0)   //Defines the components that make up the Node Class/Objects
{
    val = i;                        //Value/Data input by the user upon creation of the Node.
    priority = currentPriority;     //Priority setting of the Node set by the user
    processId = currentId;          //Unique ID of the Node differentiating it from all other nodes
    size = s;                       //Total number of Nodes.
    next = nextptr;                 //Pointer to the Next Node (Down the Queue)
    prev = prevptr;                 //Pointer to the previous Node (Up the Queue)
}


private:

N val;              //Template variable of a value input by the user
int size;           //Size variable of the total number of nodes
int priority;       //Variable input by the user to determine where in the queue the node is placed
int processId;      //Variable automatically set when the node is created. Unique to each Node.
};

调用它的函数

void Queue::Display(void)
{   

    bubbleSort(front);

        cout << '\n';
    }

分类功能

    void bubbleSort(Node<T> *&start)
{
    int size = back->getProcessId();
    int i = 0;

    Node<T> *lastSwapped = NULL;

    while (size--)
    {
        Node<T>
            *current = start,
            *prev = NULL,
            *currentSwapped = NULL;

        while (current->getPrev() != NULL)
        {
            Node<T> *after = current->getPrev();


ERROR IS HERE >>> if (*current->getPriority() > *after->getPriority())


            {
                current->next = after->next;
                after->next = current;
                if (prev == NULL)                   
                    start = after;
                else
                    prev->next = after;

                prev = after;
                currentSwapped = current;
            }           
            else
            {
                prev = current;
                current = current->getPrev();
            }
        }

        if (currentSwapped == NULL)
            break;
        else
            lastSwapped = currentSwapped;
    }
}

0 个答案:

没有答案