C/C++ :: Program That Uses Priority Structure Squishing Bug
Jun 8, 2014
quishing some bugs, and also how to go about squishing these bugs?
#include "stdafx.h"
#include<stdio.h>
#include<malloc.h>
[Code].....
Here are the errors after compiling the program.
View 7 Replies
ADVERTISEMENT
Jan 9, 2014
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
struct name {
int first;
int second;
[code] .....
whats wrong in the program i tried to return struct.
View 2 Replies
View Related
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
Nov 3, 2013
Given a set of different types of paired symbols; determine whether it is balanced or not (the opening and closing version of each type are paired correctly). Any other type of characters may appear in the input will be neglected.
For example:
(**(*[*])****) is balanced, also [{}**[]**()]** is balanced. But ((*{*)*}) is unbalanced as well as [()***[]***{*(*)}.
Write a C++ program that requires a string containing and expression as an input from the user and check for balanced bracket pairs using stack data structure.
Here is my code which give me nothing when I run it.
#include <iostream>
#include <string>
using namespace std;
class CustomStack {
[Code] ....
View 1 Replies
View Related
Mar 14, 2013
Is it possible to write a program such that it will automatically execute the function in queue base on their priority even if user programmed it randomly?
Code:
function1(){ very_important; }
function2(){ important; }
function3(){ less_important; }
int main() { // Programmed by user
function3;
function1;
function2;
//Output: Program will execute function1, 2 and lastly 3.
}
View 2 Replies
View Related
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
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
Jan 5, 2013
I have created a string array of 5 and I will use that to enter some "tasks", then I also have an integer array of 5 where i can assign priorities to the information in the string
string info[5];
int p[5];
cout<<"Enter info 1"<<endl;
cin>>info[0];
cout<<"Enter priority"<<endl;
cin>>p[0];
etc,
I want to be able to link the priorities that i assign to that string and be able to call the information that has the highest priority. I can only using iostream and string header files so far,
View 3 Replies
View Related
Jan 19, 2014
Been given an assignment to create a predictive text program. What data structure I should use for this and the steps I should take when I make the program?
View 12 Replies
View Related
Feb 13, 2015
I tried to write a menu program as a switch-case structure with a separate function for a switch-case structure itself. The outcome for it currently is an undesired one
Code:
#include <iostream>
using namespace std;
int menu(int answer);
int main()
[Code].....
The output I get is one where it's just an infinite loop of "Bad choice! Please try again later.".
View 7 Replies
View Related
Feb 5, 2015
writing this program where you can search a structure array for existing elements, add new elements to the structure array, and find and display entire elements of the array structure and all.
Right now I am stuck on adding new elements to the structure array.
#include <iostream>
#include <string>
#include <iomanip>
[Code]....
Any methods to displaying the a array structure or editing it ....
View 6 Replies
View Related
May 18, 2014
This is my program
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<math.h>
struct date
{int dd,mm,yy;}
[Code] ....
Error in Line 11:Too many types in declaration
View 2 Replies
View Related
Jun 19, 2013
how double ended priority queue be used to implement external quick sort?
View 8 Replies
View Related
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
Jan 17, 2014
This is the program below..can you spot the errors in it.. I am getting lots of errors...!!
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct student {
char name[10];
int rollnumber,result
float m1,m2,m3,total
[Code] .....
View 12 Replies
View Related
Mar 21, 2014
I have an assignment that wants me to better understand how certain calls like malloc() and free() work. I'm supposed to have one function that allocates a pool of memory for the program to use (this is the only place where I'm allowed to use the malloc function. Anyplace else is off limits, except when allocating space for data structures.) Another function needs to be defined that allocates memory from this large pool of memory that we have already allocated. A third function needs to free a block of memory when a call from function main is made and a fourth does something else (haven't gotten that far yet.) I'm not sure if it's ok or not, but I'll attach the pdf form that describes all the requirements. If that's not ok, I'll delete it.)
Anyways, when thinking of data structures to use for this particular problem, one doesn't jump out at me as being THE data structure that would be most useful. How I would imagine using it is to store the addresses currently being used as well as the block length of those addresses (so basically, each node of the linkedlist would have a pointer that points to an allocated address and another field that told the size of the allocated block of memory.) How to communicate to the large pool of memory that a certain block of memory has been allocated and shouldn't be used until a free is made on that specific block of memory.
Attached File(s)
pa3.pdf (61.07K)
View 2 Replies
View Related
Mar 2, 2013
In 83rd line message says: "Illegal Structure operation". But I didn't use any structures! How to correct it?
#include<iostream.h>
#include<conio.h>
#include<math.h>
int prime(int);
int reverse(int) ;
int power(int,int);
int rectangle(int,int);
int square(int);
int circle(int);
void tables(int);
[Code] ....
View 6 Replies
View Related
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
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
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
Nov 4, 2013
how to use a Class structure to create a program that reads in two rational numbers and adds them, subtracts, multiplies, and divides them.
View 3 Replies
View Related
Aug 27, 2013
I am trying to run a programme implementing a function with structures in c... which is:
#include<stdio.h>
#include<conio.h>
struct store {
char name[20];
float price;
int quantity;
[Code] .....
View 1 Replies
View Related
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
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
Dec 7, 2014
Why doesn't this compile?
struct hi(){
void other();
}histructure;
void hi::other(){
std::cout << "Hi!" << std::endl;
[Code] ....
Makes no sense the structure is written before the structure member function is called so why is there compile errors ??...
View 3 Replies
View Related
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