>>I guess all of you know this message..
No I don't. Post the exact error message instead of making us guess.
what compiler and os are you using? Learn to use your compiler's debegger so that you can step through the program one line at a time to see its execution.
The only problem I could spot is in main() a data overflow will occur when the value of sum reaches the limit that an integer can hold -- the results of overflow is undetermined.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Sorry, I meant the error message this one
http://img353.imageshack.us/img353/4592/60491933en2.jpg
I'm using Microsoft Visual C++
and there's no message for the debug!!
So, is it now clear my friend? I hope you'll be able to determine *kindly* the mistake in the code :shy:
You need to supply dictionary.txt. This program can't be run without it.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
OMG! my friend you can use any txt file as a sample..
ok ok these are the contents of dictionary.txt
abalone
abandon
abase
abash
abate
abater
abbas
abbe
abbey
abbot
Abbott
abbreviate
abc
abdicate
abdomen
abdominal
abduct
Abe
abed
Abel
Abelian
Abelson
Aberdeen
Abernathy
aberrant
aberrate
abet
abetted
abetting
abeyance
abeyant
abhorred
abhorrent
abide
Abidjan
Abigail
abject
ablate
ablaze
able
ablution
Abner
abnormal
Abo
aboard
abode
abolish
abolition
abominable
abominate
aboriginal
aborigine
aborning
abort
abound
about
above
aboveboard
aboveground
abovementioned
abrade
Abraham
Abram
Abramson
abrasion
abrasive
abreact
abreast
abridge
abridgment
abroad
abrogate
abrupt
abscess
abscissa
abscissae
absence
absent
absentee
absenteeism
absentia
absentminded
absinthe
absolute
absolution
absolve
absorb
absorbent
absorption
absorptive
abstain
abstention
abstinent
abstract
abstracter
abstractor
abstruse
absurd
I'm sorry, for being not so detailed in my question.. I have some network conection errors :\
Well, I hope that's enough informations :)
thanks in advance :)
Well, I was kind of guessing I could, but I didn't know whether there were any restrictions on the text file (i.e. certain format, must be alphabetized, etc.).
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
I think your problem may be here:
for(tmp = HT[loc].link, tmp2=tmp->link; tmp2; tmp2 = tmp, tmp = tmp->link)
if(tmp2->data > x)
break;
tmp is allowed to become null before exiting the for-loop, then you try to access tmp->link when tmp is null.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
I don't think so my friend, I did tried this program for integers and it does work efficiently
when I change the input to string it doesn't work!! :'(
Change this for-loop:
for(tmp = HT[loc].link, tmp2=tmp->link; tmp2; tmp2 = tmp, tmp = tmp->link)
if(tmp2->data > x)
break;
to a while loop:
tmp = HT[loc].link;
tmp2=tmp->link;
while (tmp2)
{
if(tmp2->data > x)
{
break;
}
tmp2 = tmp;
if (tmp == NULL)
{
cout << "tmp is null" << endl;
}
tmp = tmp->link;
}
and run it with the input file you posted here. See if the message in line 13 displays. It did for me. This may not be where the problem is, but it looks to me that this is where it is crashing.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
>>any suggestions ?
New insert function. Note that this version does not use HT[n], but starts at HT[n].link -- simplifies the code.
void insert( int x )
{
int loc;
loc = x % tSize;
Node * tmp2 = 0;
tmp = HT[loc].link;
while( tmp )
{
if(tmp->data > x)
break;
tmp2 = tmp;
tmp = tmp->link;
}
Node *tmp3 = new Node(x);
if(tmp2 == 0) // insert at head of list
HT[loc].link = tmp3;
else if(tmp == 0) // insert at tail
tmp2->link = tmp3;
else
{ // insert somewhere in the middle
tmp3->link = tmp2->link;
tmp2->link = tmp3;
}
HT[loc].count++;
} // end function insert
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343