簡體   English   中英

優先級隊列實現的編譯器錯誤

[英]Compiler error with priority queue implementation

我正在做一個無需使用#include庫即可創建優先級隊列的任務。 我寫了一些函數,遇到了一個我無法解決的問題。

// CSCI 2530
// Assignment: 6
// Author:     
// File:       pqueue.cpp
// Tab stops:  ***

// **Say what this program does here.  (replace this comment)**


#include <cstdio>
#include "stdafx.h"
#include "pqueue.h"

using namespace std;



//Structure PQCell holds an item (item), priority (priority) and
//a pointer to the next item in the priority queue.

struct PQCell 
{
    ItemType item;
    PriorityType priority;
    PQCell* node;

    PQCell() : item(0), priority(0), node()
    {
    }
};

//Checks the the first element of the linked list (q) for
//a NULL value. If the list is empty this first element will be NULL.

bool isEmpty(const PriorityQueue& q)
{
    if (q.next == NULL)
    {
        return false;
    }
    return true;
}
//-------------------------------------------------------------------


void insertCell(PQCell*& L, ItemType x, PriorityType p)
{
    PQCell cell;
    cell.item = x;
    cell.priority = p;
}



void insert(PriorityQueue& q, ItemType x, PriorityType p)
{
    insertCell(q, x, p);
}


int main()
{



    return 0;
}

在上面的代碼中,它顯示了程序的主文件,其中我編寫了“ insert”和“ insertCell”函數。

調用時,insertCell函數應該將新的單元格插入PriorityQueue中。 但是,當我嘗試調用插入單元格時,它給了我錯誤(如上圖所示)。

另外,這是我為此項目創建的頭文件

// CSCI 2530
// Assignment: ***
// Author:     ***
// File:       ***
// Tab stops:  ***

// **Say what this program does here.  (replace this comment)**


#include <cstdio>
using namespace std;

struct PQCell;
//Type definitions

typedef const char* ItemType;
typedef double      PriorityType;

struct PriorityQueue
{

    PriorityQueue* next;

    PriorityQueue()
    {
        next = NULL;
    }
};
//Prototypes

bool isEmpty(const PriorityQueue& q);
void insert(PriorityQueue& q, ItemType x, PriorityType p);

另外,這里是分配說明的鏈接..... http://cs.ecu.edu/~karl/2530/spr18/Assn/Assn6/assn6.html

您嘗試將PriorityQueue的引用作為第一個參數傳遞給insertCell,此函數需要一個PQCell作為參數。

我想說的是您的insertCell應該詢問PriorityQueue,以便您可以將其推入

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM