C++ :: Creating Priority Queue Of Objects Transaction As A Variable Of Store Class

Dec 4, 2013

I've got 2 classes, Store and Transaction and I would like to create a priority queue of objects Transaction as a variable of Store class.

My store.h
#ifndef __STORE_H_INCLUDED__
#define __STORE_H_INCLUDED__
#include <queue>
using namespace std;
#include "Transaction.h"
struct TransactionCompare;

[Code] ....

The error im getting with this set up is

error C2664: 'bool TransactionCompare::operator ()(const Transaction &,const Transaction &)
const' : cannot convert parameter 1 from 'Transaction *' to 'const Transaction &'

View 6 Replies


ADVERTISEMENT

C++ :: Thread Safe Class - Queue Of Objects

May 7, 2013

I am new to C++ programming and i have a small assignment.

How to implement a thread safe class to manage a queue of objects. Accessing the front of the queue should be a blocking operation when the queue is empty.

View 4 Replies View Related

C/C++ :: Priority Queue Without STL

Nov 28, 2014

How to build a FiFO queue without using the STL (done that no problem), get it to dequeue (again, done that no problem). However, to get those extra marks, I need to be able to order it using a priority system.

I've tried ordering the NodeDequeue class that I'll show at the bottom of this post, but I just cannot get it to order appropriately. The closest I have got is everything in order but I lose a Node from the memory completely. So, that's no good.

The most logical idea I have thought of right now is to send the largest number to the back of the queue each time it's iterated, eventually, the largest number will end up at the front.

class PriorityQueue : public Queue {
public:
Node* NodeDequeue(void) {
Node* tmp = front;
Node* seek = tmp->getPrev();

[Code] .....

View 3 Replies View Related

C++ :: Decrease Key In STL Priority Queue

Jan 19, 2013

I'm trying to implement Prim's Algorithm and for that I need to have a decreaseKey method for a priority queue (to update the key value in a priority queue). Can I implement this in the STL Priority Queue?

This is the algorithm I'm following:

for each vertex u in graph G
set key of u to INFINITY
set parent of u to NIL
set key of source vertex to 0
en-queue to priority queue Q all vertices in graph

[Code] .....

View 1 Replies View Related

C++ :: How To Resort Priority Queue

Nov 4, 2013

I've got a priority queue of items who, from time to time, returns a different comparison result. Any way to re-sort a priority queue who is storing them?

Example:

#include <cstdlib>
struct Random {
bool operator<(const Random&) const { return !(rand()&1); } };

View 10 Replies View Related

C :: Double Ended Priority Queue

Jun 19, 2013

how double ended priority queue be used to implement external quick sort?

View 8 Replies View Related

C++ :: Implementing Functions In Priority Queue

Oct 28, 2014

I know queue but with priority queue i am really amateur. How to implement some functions in priority queue.

template <class T> class PRIORITY_QUEUE {
private:
T *items; // array of queue items
int rear;
int maxSize; // maximum size of queue

[Code] ....

and what does heapify mean???

View 8 Replies View Related

C++ :: Creating A Class That Would Implement Concept Of Double Linked List Like A Queue

Jun 15, 2013

Well, basically, what I've been doing was creating a class that would implement the concept of Double Linked List, but that would behave like a queue ( the STL implementation is deque, or Double Ended Queue ).

The problem occured when I have been trying to generalize the class using templates. I mean, why use only integers ? Why not double or char or what not ?

Worked perfectly before including all the template stuff..

// Source.cpp <=> Main.cpp
#include <iostream>
#include "DList.h"
using namespace std;
int main(void) {
DList<int> *list;
list = new DList<int>();

[Code] .....

The errors returned by the compiler:

Error1error C2955: 'Node' : use of class template requires template argument listc:usersjumperdesktopc++ otherdouble linked listdouble linked listdlist.h6
Error2error C2955: 'Node' : use of class template requires template argument listc:usersjumperdesktopc++ otherdouble linked listdouble linked listdlist.h6

View 6 Replies View Related

C :: Maintains A Priority Queue Of Music Tracks

Jan 4, 2014

write a program, pfpq.c, that maintains a priority queue of music tracks (songs) and ratings. The struct is given by:

Code:

struct track
{
char artist[20];
char title[20];
int rating;
};

The program is only designed to demonstrate the concept so get the user to enter a small number of tracks and create a priority queue. (Use an empty string title or an empty string artist to end the program). Print the priority queue as it grows. Your program should initially ask the user if they wish to order the priority queue by rating in ascending order, or by rating in descending order, or if they wish to order the priority queue by artist name. Then build the priority queue accordingly. in the last case, "if they wish to order the priority queue by artist name." which is case 3. How do I sort the priority queue by artist name using in the following code.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pqueue.h"
struct track
{
char artist[20];
char title[20];
int rating;
}

[code]....

View 11 Replies View Related

C++ :: Priority Queue - Inserting Into Bottom Of Array

Jan 24, 2013

i am working on creating a priority queue, i seem to have done the algorithm for inserting from the top correctly but the algorithm for inserting from the bottom doesnt seem to work it just overwrites the existing data.

below is my code :

list is an array and listlength is the size of the array declared as a integer

void inserttop(string task) {
//int head = 0 ;
string temp ;
listlength++ ;
for (int i = 1; i < listlength; i++) {

[Code]...

View 2 Replies View Related

Visual C++ :: Priority Queue Sorting Incorrectly

Jan 27, 2013

So i have been banging my head against a wall with this problem for awhile. I have also copy and pasted direct examples from the internet but nothing seems to sort it right.

Node Header

Code:
#ifndef _NODE_H
#define _NODE_H
#include <stdio.h>
class Node {
public:
Node();
Node(int weight, char value, Node* left = NULL, Node* right = NULL);

[Code] ....

View 1 Replies View Related

C++ :: Using Parametered / Templated Comparison Object For Priority Queue

Aug 19, 2013

On several occasions in my project, I need to sort elements (indeces) based on their linked values. Those values are stored in an array. This means the comparison looks like this:

bool operator()(int i, int j) { return someArray[i] > someArray[j]; }

Because this form returns often but someArray may differ, I wrapped this in a template class:

template<class T>
struct sorter {
std::vector<T>& data;
sorter(std::vector<T>& __d) : data(__d) {}
bool operator()(int i, int j) const { return data[i] > data[j]; }
};

Now, I want to use this in a different way: I want to select the K indeces with the lowest value from someArray attached to it. My idea was to build a priority_queue, push the first K elements and then compare all the next elements to PQ.top(), as such:

INDEX t(0);
for (; t < someLimit; ++t) {
pq.push(t);
if (pq.size() == K) break;
}
for (; t < someLimit; ++t) {
if (someArray[t] < someArray[pq.top()]) { pq.pop(); pq.push(t); }
}

My problem, however, is the definition / initialization of the priority_queue object. My first idea was simply std::priority_queue<INDEX> pq(sorter<VALUE>(someArray));, but calling any function on pq provides the error "expression must have class type" (?) when hovering over pq.

My second guess, std::priority_queue<INDEX, std::vector<INDEX>, sorter<VALUE>(someArray)> pq;, provides the error 'expected a ')'' when hovering over someArray.

What is the correct way to initialize this data structure?

View 1 Replies View Related

C++ :: Heap And Priority Queue (Array Not Storing Digit)

Feb 27, 2015

This assignment is about Heap and PQ's to sort out jobs inside a printer. I'm far from finishing the assignment but the most important part isn't working. My issue is that nothing is getting stored inside the array. I keep getting crashes and at this point I'm not sure what to do. I notice that my destructor runs right after my "addJob" Function finishes, which is destroying the memory. Which might be why nothing gets stored inside OR I think my implementation of Heap/PQ is wrong.

Functions inside my test.cpp aren't properly done, they are made just to see if something is stored inside.

1. Check if I created the array correctly [PQtype.cpp / Heap.h/ PQType.h]
2. Am I even using/storing into the array. [Test.cpp "addJob" Function]
3. I'm also new to working with Class Templates.

PQType.h
template<class ItemType>
class PQType {
public:
PQType(int);
PQType(const PQType&); /

[Code] .....

View 4 Replies View Related

C++ :: Creating Array Of Pointers To Base Class To Point To Derived Class Objects Dynamically

Jan 16, 2013

Please consider the following code :

#include <iostream>
using namespace std;
class superclass;
class subclass1;
class subclass2;

[Code] ....

As you can see I want to create a dynamically allocated storage of references to a parent class each of which can then point to a child class, how ever I do not know how to extract the child class out again from that array so i may access its variable b.

View 2 Replies View Related

C/C++ :: Error In Circular Vector Implementation Of Sorted Priority Queue

Mar 1, 2015

There appears to be some kind of error in by removeMin() function. Inserting items seems to work just fine but attempting to remove any items gives me the error "vector subscript out of range".

Here is my SortedPQ class... Below it you will find the quicksort implementation, in case looking at it is necessary.

template <class Type>
class SortedPQ {
private:
int front;
int rear;
vector<Type> V;
public:
SortedPQ(void) : front(-1), rear(-1), V(0){}

[Code] ....

View 1 Replies View Related

C++ :: Use Array To Store Class Objects?

Feb 11, 2013

So starting with the Item.h file :

#ifndef ITEMH
#define ITEMH
using namespace std;
class Item

[Code]...

I think I'm getting the wrong idea about strings. I thought I could add data just by using '+=' but apparently not.

View 4 Replies View Related

C/C++ :: Unable To Use Priority Queue Sorting In Reverse Order To Take Vector Or 2D Array

Aug 7, 2014

I'm trying to use a priority queue sorting in reverse order to take a vector or 2d array. The problem is that I want to sort by the vector/array cell value but keep the reference to the vector/array index of the value. I don't know quite howto keep them both related so when I pop. I can find the corresponding cell.

priority_queue<int, vector<int>, greater<int> > Open;

View 2 Replies View Related

C/C++ :: Creating A Class To Store Value That Represents Number Of Hours / Days Worked

Feb 22, 2014

Create a class to store a value that represents number of hours worked and number of days worked. Must ensure that the two representations are always consistent. I have to create 2 files, I'm pretty sure: a .cpp and a .h

This is what I have so far for my .h file (I know it's NOT functional...yet):

#include <iostream>
using namespace std;
class NumDays {
private:
double hours;
double days;

[Code] ...

I don't know how to start / create this .cpp file to define the variables.

View 3 Replies View Related

C++ :: Creating A Class Variable With A String?

May 12, 2013

I have defined a class in a header file; just the class, no templates involved. I have a program where I'm reading in data in string format. Each string consists of a word, a delimiter, and a variable name. Example:

cajun/mustard

I want to take that string and make it the variable name of that class type. It would be implemented along the lines of:

Code:
string str;
//read/process string here, get:
str = "mustard";
createName(str);
//pass string to creator function When the function is called, I should get the variable:
Class mustard;

Thing is, I'm not supposed to know beforehand what the variable names are, only that I create them as they are read in. It could be mustard, it could be Maynard_James_Keenan, it could even be bazinga.

My problem is, what do I do for createName()? I've looked into the concepts of pairing, Factory implementation, and maps, but I don't think they answer my question.

(P.S. if I run into the same variable name being read in twice, what steps can I take to make sure that a duplicate variable isn't created? Do I need to add in code, or does the compiler know to watch for multiple variables of the same name?)

View 6 Replies View Related

C++ :: Store Reference To Const Object In Class As A Member Variable?

May 27, 2014

i want to store reference to a const object in my class as a member variable, as follow:

I basically want a readonly reference to |Data| in Device object.

Code:

class Device {
Device(const QList<QSharedPointer<Data>> & dataList) : _listRef(dataList) {
} protected:
const QList<QSharedPointer<Data>> & _listRef;
}

This does not allow me to initialize _listRef as something like NULL when it is not applicable.Also, i must change all my constructors and its child class to include an initialization of _listRef!!

What is the alternative? Is pointer the nearest? which of the following should be used?

Code:
const QList<QSharedPointer<Data>> * _listRef;
or
const QList<QSharedPointer<Data>> *const _listRef;
or
const QSharedPointer<QList<QSharedPointer<Data>>> _listRef; ????

View 7 Replies View Related

C++ :: Creating STL Queue Of Arrays?

Dec 3, 2013

Is there any possible way to create an STL queue of arrays? I tried

queue<int[]>q;

It didn't work?

View 2 Replies View Related

C++ :: Store A Reference Variable As Member Variable Of Interface Object

May 1, 2013

I am having trouble compiling my interface. I am trying to store a reference variable as a member variable of the interface object. Compiler says that the variable has not be initiated correctly.

LCD inherits from VisualInterface which is expecting a DisplayDriver object to be passed in (DisplayDriver is another interface, but thats not important).

I pass the displayDriver object in when LCD is instantiated in maininterfaces.zip

I was pasing it before as a pointer but was told that this could cause me problems with memory leaks and a reference was better, but now I cant seem to get it to compile.

View 11 Replies View Related

C++ :: Store Function To A Variable And Call It Using That Variable?

Oct 15, 2013

I want to store few different functions to a variable for different structs/classes and then call it later using that variable, is it possible? something like

struct item {
int ID;
int special; // for function
};

item Key;
Key.special = UseKey(KEY_KING);

// now when I want to call function "UseKey(KEY_KING)" I want to use "Key.special", like this

if(iCurrRoom == ROOM_KING)
Key.special;
else if(iCurrRoom == ROOM_DRAGON)
Fireball.special;

View 5 Replies View Related

C++ :: How To Store Objects To Program

Nov 14, 2013

I've started programming my little program called vLibrary (program I want to make for the library in my city) and after I m done with console application I will try to implement wxWidgets.My program will be able to add new users to the system, new books and new librarians.

Now, I m confused what data types to use and how to store objects (newly created users, books etc) to my program so later on they can log in the system etc. Logic of the program is completely clear to me but I m not sure how to make array of objects and store them in memory or in a certain file, how to store password and make some kind of encryption etc.which data structure from STL should I use and how.

View 2 Replies View Related

C++ :: Store Address Of Objects

Oct 27, 2014

I'm using the SDL library and trying to match the C++11 standards... Anyway, I thought about a vector where I store all the addresses of game instances, so I can access them anytime... I tried with this function:

int instance_new(std::vector<uintptr_t> &instance_id, unsigned &instance_size, Instance *pointer) {
instance_id[instance_size] = reinterpret_cast<std::uintptr_t>(pointer);
instance_size++;
instance_id.resize(instance_size);
return 0;
}

Where "Instance" is the 'parent' class of various child classes like the player. So, if I have to search the existing of a thing in my game, I should check if the address references to an instance of class. How can I do this?

View 1 Replies View Related

C/C++ :: Container To Store Objects Under (unique) ID

Jun 14, 2014

I searching for a container/collection, that can access very fast to objects with the associated id.

Arrays are a bad idea, because it can be that I must store objects with a big id for example 9394034, so the array would be to big.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved