简体   繁体   中英

Compiler error with priority queue implementation

I am working on an assignment that is to create priority queue without using the #include library. I have written a few functions and have ran into a problem that I cant figure out.

// 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;
}

In the code above it shows the main file of the program where I have written a "insert" and a "insertCell" function.

The insertCell function is supposed to insert a new cell into PriorityQueue when called upon. However, when I try to call on insert cell it gives me the error(shown in the image above).

Also, here is the header file which i have created for this project

// 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);

Also, here is the link to the assignment instructions..... http://cs.ecu.edu/~karl/2530/spr18/Assn/Assn6/assn6.html

You are trying to pass a reference of PriorityQueue as first argument to insertCell, this function needs a PQCell as argument.

I'd say that your insertCell should ask for PriorityQueue instead, so you can push into it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM