优先队列实现的编译器错误
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);
还有,这里是link赋值说明.....
http://cs.ecu.edu/~karl/2530/spr18/Assn/Assn6/assn6.html
您正在尝试将 PriorityQueue 的引用作为第一个参数传递给 insertCell,此函数需要一个 PQCell 作为参数。
我会说你的 insertCell 应该请求 PriorityQueue,所以你可以推入它
我正在处理一项任务,即使用#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);
还有,这里是link赋值说明..... http://cs.ecu.edu/~karl/2530/spr18/Assn/Assn6/assn6.html
您正在尝试将 PriorityQueue 的引用作为第一个参数传递给 insertCell,此函数需要一个 PQCell 作为参数。
我会说你的 insertCell 应该请求 PriorityQueue,所以你可以推入它