0 Replies - 1018 Views - Last Post: 03 November 2009 - 07:47 AM Rate Topic: -----

#1 ColeS  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-November 09

Error Trying to Insert a Struct into priority_queue

Posted 03 November 2009 - 07:47 AM

I am trying to do an assignment to encode a text file into a Huffman tree. I have run into a snag though. When I try to push the struct that contains the char, frequency, left and right childs into the priority queue i get errors c2784 and c2676.

#include <iostream>				  
#include <string>												 
#include <fstream>
using namespace std;
#include <functional>
#include <queue>
#include <vector>


typedef std::priority_queue<
	 int,
	 std::vector<int>,
	 std::greater<int>
> min_heap_of_ints;

struct val{char symbol; int frequency; val * right; val * left;};

priority_queue<val, vector<val>> buildMinHeap(priority_queue<val,vector<val>> t)
{
	
	return t;
}

val Huffman(vector<val> c)
{
	priority_queue<val , vector<val>> t;
	val temp;
	for(int i = 0; i < c.size(); i++)
	{
		temp = c.front();
		t.push(temp);	   //this is what causes the errors to be thrown
		c.pop_back();
	}
	priority_queue<val, vector<val>> returnVal;
	returnVal = buildMinHeap(t);
	return returnVal.top();
}


int main()
{
	ifstream in("Huffman.txt");
	vector<val> frequency;
	vector<char> input;
	char temp;
	for(int j = 0; !in.eof(); j++)
	{
		input[j] = getchar();
		temp = input[j];
		bool found = false;
		for(int i = 0; i <= frequency.size(); i++)
		{
			if(temp == frequency[i].symbol)
			{
				frequency[i].frequency++;
				found = true;
			}
			else if(found = false && i == frequency.size())
			{
				frequency[i].symbol = temp;
				frequency[i].frequency = 1;
			}			
		}
	}
	in.close();

	//call the huffman encoding

	//write the encoded file

	return 0;

}


more specifically the errors that i get are

Error 3 error C2784: 'bool std::operator <(const std::queue<_Ty,_Container> &,const std::queue<_Ty,_Container> &)' : could not deduce template argument for 'const std::queue<_Ty,_Container> &' from 'const val' c:\program files\microsoft visual studio 9.0\vc\include\functional 143 hw4

and a about 8 more like it

and

Error 12 error C2676: binary '<' : 'const val' does not define this operator or a conversion to a type acceptable to the predefined operator c:\program files\microsoft visual studio 9.0\vc\include\functional 143 hw4


I need help on this badly. I feel that i need to define what is being compared but i do not know how to do that in the struct.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1