# hash function help!!!!

• 12 years ago

Can anyone help me to write up a hash function* that uses the 6 digit grid reference as a key. Using this function and the hill details already generated, add the hill details to another array, this time of 63 elements and this will be my hash table.

this is my piece of code for the linklist.cpp

using namespace std;

last = NULL;
count = 0;
}

void LinkedList:: insertNodeAtStart(int height, int distanceFromHome, bool climbed, int gridReference){
Node *nextNode;
nextNode = new Node;
nextNode->height = height;
nextNode->distanceFromHome= distanceFromHome;
nextNode->climbed= climbed;
nextNode->gridReference= gridReference;

count++;

if(last == NULL){
last = nextNode;
}
}

void LinkedList:: insertNodeAtEnd(int height, int distanceFromHome, bool climbed, int gridReference ){
Node *lastNode;
lastNode= new Node;

lastNode->height = height;
lastNode->distanceFromHome= distanceFromHome;
lastNode->climbed= climbed;
lastNode->gridReference= gridReference;

count++;

head= lastNode;                             //if this is the only node, make it first and last.
last= lastNode;
}
else{
last->link= lastNode;                 //make the link of the last node point to our new node
last= lastNode;                       //make last or newly created node.
}
}

return count;
}

}

if(count > 0){

delete temp;
count--;
}
else{
cout<<"There are no nodes to delete."<<endl;
}
}

int noOfNodes=getNodeCount();
Node *current;
current= getFirst();

for(int i=0; i<=noOfNodes-1; i++){
if(number==current->data){
cout<<"found"<<endl;
return true;
}
else{
}

}
cout<<"Number is not in the Linked List"<<endl;
return false;
}*/

Node *current, *next;                                      //two pointer to help maipulate position
if(current->data== number)                                 //if the number is first in the list
{
delete current;                               //delete the node which used to be head
count--;                                     //reduce count by one
return;
}

next=current;                                               //make next = the new head node (current)
while(next!=NULL)                                           //iterate through until no more nodes
{
if(current->data==number)                        //if the data in current is the number
{
delete current;                 //delete the current node
count--;
return;
}

next=current;                                    //keep iterating until the number is found
}
}*/

int noOfNodes= getNodeCount();
Node *current;

for(int i=0; i<noOfNodes;i++){
delete current;
count--;
}
}

int noOfNodes= getNodeCount();
Node *current;

for(int i=0; i<noOfNodes; i++){
cout<<"Height: "<<current->height<<endl;
cout<<"Distance from Home: "<<current->distanceFromHome<<endl;
cout<<"Climbed: "<<current->climbed<<endl;
cout<<"Grid Ref: "<<current->gridReference<<endl;
cout<<"-------------------"<<endl;
}
}

void LinkedList::insertNodet(int height, int distanceFromHome, bool climbed, int gridReference){

Node* previous= NULL;
Node* temp= new Node();
count++;

temp->height= height;
temp->distanceFromHome= distanceFromHome;
temp->climbed= climbed;
temp->gridReference= gridReference;

if(count==1)
{
last= temp;
return;
}
do{
if(current->height<temp->height)
{

{
return;
}
else
{
return;
}
if(current==last)
{
last= temp;
return;
}
}
previous=current;

}
while(current!=NULL);
}

Node *swap;

swap= current;
current=next;
next=swap;
};

{

{
int noOfNodes= getNodeCount();
Node *current;
Node *nextNode;

for(int i=0;i<noOfNodes;i++){
if(current=NULL){
cout<<"No hills in list"<<endl;
return;
}
if(current->height>nextNode->height){
swap(current, nextNode);
}
}

{
int noOfNodes= getNodeCount();
Node *current;
cout << "Number of Nodes == " << noOfNodes << endl;
for(int i=0; i<noOfNodes && current != NULL; i++)
{
cout<<"Height: "<<current->height<<endl;
cout<<"Distance from Home: "<<current->distanceFromHome<<endl;
cout<<"Climbed: "<<current->climbed<<endl;
cout<<"Grid Ref: "<<current->gridReference<<endl;
cout<<"-------------------"<<endl;

}*/

• 12 years ago

You can also use STL;  <hash_map> or <hash_set> or even <map>. See MSDN for infos.

### Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

### Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Walking on water and developing software from a specification are easy if both are frozen.”