Sorry I haven't been around for a while, I've been
very busy.
I'm having some issues with a program for my C++ class.
The assignment is to create a templated array class
( Which I have done ) and then to import the array from
a file of about 40,000 words and sort the words using
shell sort, then using a sub-linear search algorithm
( I'll probably use binary-search ) find a user-input
word in the file.
My issue is that it works fine with my smaller test file.
containing a sequence of about 20 3-character strings. But,
when I switch to the large file, it hangs up. After a massive
amount of debugging, I have found that it's hanging up on the
import for some reason and I have no idea why. I will paste
the template class in a spoiler, but it generally works the
same way as standard subscripted arrays with a constructor.
Array<T> ( size_t pSize, const T& value = T() ); Array<T> (); Array<T> ( const_iterator first, const_iterator last ); Array<T> ( const Array &a );
Spoiler
MAIN:
/******************************************************************************/
// MAIN
int
main( int argc, char * argv[] )
{
/*******************************************************
**** VARIABLES ****
*******************************************************/
Array<string> a( 5 );
/*******************************************************
**** BODY ****
*******************************************************/
cout << "Importing Words to array... ";
importWords( a );
cout << "done.\n";
cout << "Sorting Array... ";
//a = shell( a );
cout << "done.\n";
//cout << a;
}
bool
importWords( Array<string> &a )
{
int i = 0;
string tmp;
ifstream fp( "./words.txt" );
if( fp.is_open() ) // Open the file
{
/* Are there remaining Lines? */
while( fp >> tmp && !fp.eof() )
{
// Is it out of bounds?
if( i >= (signed)a.size() )
{
a.push_back( "0" );
}
/* Populate the array */
a[i++] = tmp;
}
fp.close();
return( true );
}
return( false );
}

New Topic/Question
Reply




MultiQuote







|