Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Pointer to Array (http://www.go4expert.com/forums/pointer-to-array-t7797/)

qiqinuinaifen128 11Dec2007 13:26

Pointer to Array
 
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


All times are GMT +5.5. The time now is 02:22.