【发布时间】:2018-03-22 17:35:36
【问题描述】:
我正在处理一项使用#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 和 PQCell 是完全不相关的类型,但您正试图将 PriorityQueue 传递给一个函数,该函数接受指向 PQCell 的指针。你认为这会如何运作?
-
我试图复制您的屏幕快照并粘贴到我的 IDE 中,但我的 IDE 不理解屏幕快照。没有代码作为文本 == 没有帮助。
标签: c++ linked-list priority-queue