[英]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.