All pastes #584733 Raw Edit

Heron

public cpp v1 · immutable
·published 2007-06-22 22:14 UTC
rendered paste body
// the program is looping infinitely when it gets here:	for(unsigned int i = 0; i < ng1_docs->size(); ++i)	{		if(VectorContainsNum(ng2_docs, (*ng1_docs)[i]))		{			shared_docs.push_back((*ng1_docs)[i]);		}	}// and the VectorContainsNum function:...bool VectorContainsNum(vector<unsigned int>* vec, unsigned int num){	if(vec == NULL || vec->size() == 0)		return false;	// this function assumes vec is sorted!	unsigned int high = vec->size()-1;	unsigned int low = 0;	unsigned int pos = (high+low)/2;	while(low < high-1)	{		if(num > (*vec)[pos])			low = pos;		else if(num < (*vec)[pos])			high = pos;		else			return true;		pos = (high+low)/2;	}	if((*vec)[low] == num)		return true;	else if(low != high && (*vec)[high] == num)		return true;	return false;}