Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointer to Array

Status
Not open for further replies.

qiqinuinaifen128

Programmer
Dec 9, 2007
20
SG
Hi there,

i need help for the pointer to array...Actually i have create my hash table and i can successfully get the hash key for the word i want to store, now i want to create a one dimension array and

i use below command to create my hashtable, get the hashkey and add the word that i want to store into the hash table

Code:
//create hash table
Hash::Hash (int hashSize)
{
this->hashSize = hashSize;
table = new int [hashSize]
for (int i = 0; i <hashSize; i++)table[i]=-1;
word = new char *[hashSize];
for (int i = 0; i <hashSize; i++)word[i]=Null;
}
//and i use this command to get the hash key
int Hash::getHashCode(char *word)
{
unsigned int h = word[0]
for(int i = 1; i <strlen(word); i++)
{
h += (h*32+word[i])%hashSize;
}
return(h%hashSize)
}
//store word into hash table
woid Hash::add(char *newWord)
{
int i = getHashCode (newWord);
while (table[i] != -1) i ++;
word[i] = new char [strlen(newWord} + 1];
strcpy (word[i, newWord);
}

[/code ]
[code]
getHashCode("PrintfName");//get the hashkey for "PrintName"
hash->add("PrintfName");//store the PrintName to hashtable


After doing the above command, i have added "PrintName" in to hashtable and have a hash key of 12, and if i have set the table[12] = 12;and i crete an singer dimemsion array node[1000]

How can i store the "PrintName" function in to the node[12],
what command should i use in order to make table[12] point to the node[12]

I hope that i could get help from here.

Many Thanks For Reply


Singapore Swimming Lessons
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top