hi, im new in programming and C++ and i have a homework and i need a little help on how to do it will u please just tell give me some suggestions on what i should do and ill try to do it myself

This is what i have to do
In this assignment you are to implement a priority queue using a dynamic array as its implementation. The class specification file, priorityQueue.h, is given and should be used as your guideline. You must add the implementation file, priorityQueue.cpp, and create the driver file p06.cpp.

Program Requirements
§ Implement the class methods.
§ Check if memory allocation was successful each time you allocate, but do not handle the case when allocation fails.
§ Be aware of memory leaks.


and i have a header file given and i am supposed to implement the classes and create the driver file

i have attached the files
priorityQueue.h - the header file given
p06.doc - the question
priorityQueue.cpp - my incomplete code for the implementation file

will some one please help me or tell me what to do in the next 12-13 hours so i can do that and get the program done by the due time tomorrow.

Thanks
:cheesy:

Recommended Answers

All 11 Replies

if performance is not of great concern, you could do one of the following:
a. when you add an item to the array,
1. add it as the last element.
2. compare it with the element just ahead of it; if it has a higher priority,
swap the two.
3. repeat step two till either i. you find that the element just ahead has
a higher priority or ii. you have reached the front of the array.
now to remove/return the item with the highest priority, you know
that it is at the front of the array.
b. when you add an element add it at the back, as the last item.
to find the element with the highest priority, do a linear search.
with either of these approaches, the time taken to start with an empty
priority queue, add N elements and then remove N elements would be
O(N*N) - ie quadratic time.

to get a more efficient implementation ( O( N*log(N) ) ), you would
need to use a heap data structure; i am certain, it would be there
in one of your your text books.

i would suggest that you start of by implementing a dynamically
resizeable array first. make sure that it is working. and then
implement the priority queue on top of it.

im sorry but, i dont really get u

for suggestion a
let us say your queue (numbers are priorities, lower numbers indicate higher priority) looks like this:
2 5 8 11 16 23 32
and you want to add 14.
add it at the end to get 2 5 8 11 16 23 32 14
compare 14 with 32, priority is higher, so swap them to get 2 5 8 11 16 23 14 32
compare 14 with 23, priority is higher, so swap them to get 2 5 8 11 16 14 23 32
compare 14 with 16, priority is higher, so swap them to get 2 5 8 11 14 16 23 32
compare 14 with 11, priority is lower, so let things beso after add, you get a sequence sorted on priorities.
one with the highest priority is right in front.

hmm, do i have to swap them, im just supposed to find the index of the smallest time after the one im adding.

and the array is supposed to remain random i guess

will u please help me on what i should do in the ScheduleQueue(const ScheduleQueue& copy) thing, i dont really get what im supposed to copy and where

sorry about the last minute questions but ive been trying to do this program for the whole week and i have to submit it today and my friends are clueless about it too and i found out about this site yesterday night, wish i knew about it earlier.

this is how far ive gotten till now, some one please tell me what else i have to do and whats wrong there. there seems to be something wrong and i get a lot of errors and im not sure what else i have to do there either.

please post
a. what are the errors you get
b. what do you think is wrong?

i did this,

int ScheduleQueue::NextItemIndex() const{
// returns the index of the item with the next lowest time, -1 if
// there are no more items

int minIndex = -1;

for(int i = 0; i <= lastIndex; i++){
if(items.GetHeatTime() < items[minIndex].GetHeatTime()){
minIndex = i;
}
}
return(minIndex);
}

there were no errors around that area so i think it works.

But i dont know what to do with the copy thing ,


ScheduleQueue::ScheduleQueue(const ScheduleQueue& copy){
        // creates a copy of the parameter queue if not empty
       

    }

and this,

ScheduleQueue operator =(const ScheduleQueue& rhs){
        // assigns the parameter queue to the current queue, by deep copying it
    
    }

these two functions are the copy constructor and the overloaded assignment operator.
these would be explained in every C++ beginner's book, including your text book.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.