Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
error C2664: 'void std::queue<_Ty>::push(int &&)' : cannot convert parameter 1 from 'node' to 'int &&'
bold line the last line

#include "StdAfx.h"
#include<string>
#include<queue>
#include<iostream>
using namespace std ;
#define ARRAY_SIZE 20

class node
{
public:
	int weight ;
    char value;
	const node *child0;
	const node *child1;

	node( char c = 0, int i = -1 ) 
	{
		value = c;
		weight = i;
		child0 = 0;
		child1 = 0;
	}

	node( const node* c0, const node *c1 ) 
	{
		value = 0;
		weight = c0->weight + c1->weight;
		child0 = c0;
		child1 = c1;
	}

		bool operator<( const node &a ) const {
		return weight <a.weight;
	}
  void traverse(string code="") const
	{
		
	if ( child0 )
	{
		child0->traverse( code + '0' );
		child1->traverse( code + '1' );
	} 
	else
	{
		cout <<" " <<value <<"	  ";
		cout <<weight;
		cout <<"	 " <<code <<endl;
	}
}

};

int main()
{
	float hh [100] ;
	int i = 0 ;
	int n = 0 ;
	string sentence = " " ;
	float count[256] = { 0 } ;

	 cout << "Enter your sentences ( End the sentence with . ): " << endl ;
	 getline(cin,sentence);

  for( int n = 0 ; n < sentence.length() ; n++ )
  {
    count[sentence[n]]++ ;
  }

  float mm = sentence.length() - 1 ;

  for ( n = 0 ; n < 256 ; n++ )
  {
    if ( isalpha ( ( char ) n ) )
    {
      cout << ( char ) n << " has " <<  count[n] << " occurrences " << " and has   " << count[n] / mm << endl ;
	
		hh[ n ] = ( count[ n ] / mm ) ;
		i++ ;
			 cout << "yay" << hh[n] << endl ;
	}
	int counter = 0 ;
	if( hh[n] != 0 )
	{
		counter++ ;
	}

	
  int x, y;
  float holder;

  // Bubble sort method. 
  for( x = 0; x < counter ; x++ )
    for( y = 0; y < x - 1 ; y++ )
      if(hh[y] > hh[y+1] )
	  {
        holder = hh[y+1] ;
        hh[y+1] = hh[y] ;
        hh[y] = holder ;
	    cout << hh[y] << "yay" ;
      } 	

	  queue<int>q;
	  
	  q.push(hh[y]);
	while (!q.empty())
    {
       q.front();
       q.pop();
    }

	
	while ( q.size() <1 ) {
		node *child0 = new node( q.front() );
		q.pop();
		node *child1 = new node( q.front() );
		q.pop();
		q.push( node( child0, child1 ) );
	}


  }


  
   return 0;
}
Posted
Updated 30-Jun-11 20:32pm
v2

1 solution

Well, you could provide it with an int, rather than a node address...
queue<int>q;
...
q.push( node( child0, child1 ) );</int>


BTW: Use more sensible names, sort out your indentation so your code is easier to read, and why have you still got a tracing statements in code you presumably must have debugged by now? Also, be consistent: I can tell you are pasting this together and hoping it works just from the variety of curly bracket styles: K&R, none, indented, partially indented. Sort it out. Pick a style, and stick with it. Otherwise it makes your code even harder to read.
 
Share this answer
 
Comments
yay hello 1-Jul-11 3:34am    
but i need node for tree
OriginalGriff 1-Jul-11 3:38am    
Then you either need to change the definition of "q" to allow nodes instead, or set up a new tree. If you do the former, don't come whining when it causes errors in your other code! :laugh:
Stefan_Lang 1-Jul-11 4:15am    
I don't really think it makes sense to store the nodes that you construct into a queue that held your character codes. Whatever you want to do with your stored nodes later, I doubt you would want them to be mixed up with char codes.

Also, does it actually make sense to store them in a queue? wouldn't it make more sense to store them in a type of container that would make your nodes easily retrievable, such as a map?

Create a separate container - whatever type is appropriate - and use the proper element types for that, e.g. map<int,node>
Stefan_Lang 1-Jul-11 4:10am    
I think some of the indenting problems stem from the fact that the code contains tabs. Unfortunately CP translates them to a gap with a width of 8 characters, which is rather unusual. The only way to avoid this when copying existing code is by changing your editor settings to automatically translate tabs into spaces when saving.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900