Error_code Trie::insert(const Record &new_record)
{
Error_code result=success;
if(root==NULL)
root=new Trie_node;
int position=0;
char next_char;
Trie_node *location=root;
while(location!=NULL&&(next_char=new_record.key_letter(position))!='\0')
{
int next_location=alphabetic_order(next_char);
if(location->branch[next_location]==NULL)
location->branch[next_location]=new Trie_node;
location=location->branch[next_location];
position++;
}
if(location->data!=NULL)
result=duplicate_error;
else
location->data=new Record(new_record);
return result;
}
Error_code Trie::trie_search(const Key &target, Record &x) const
{
int position=0;
char next_char;
Trie_node *location=root;
while(location!=NULL&&(next_char=target.key_letter(position))!='\0')
{
location=location->branch[alphabetic_order(next_char)];
position++;
}
if(location!=NULL&&location->data!=NULL)
{
x=*(location->data);
return success;
}
else
return not_present;
}
{
Error_code result=success;
if(root==NULL)
root=new Trie_node;
int position=0;
char next_char;
Trie_node *location=root;
while(location!=NULL&&(next_char=new_record.key_letter(position))!='\0')
{
int next_location=alphabetic_order(next_char);
if(location->branch[next_location]==NULL)
location->branch[next_location]=new Trie_node;
location=location->branch[next_location];
position++;
}
if(location->data!=NULL)
result=duplicate_error;
else
location->data=new Record(new_record);
return result;
}
Error_code Trie::trie_search(const Key &target, Record &x) const
{
int position=0;
char next_char;
Trie_node *location=root;
while(location!=NULL&&(next_char=target.key_letter(position))!='\0')
{
location=location->branch[alphabetic_order(next_char)];
position++;
}
if(location!=NULL&&location->data!=NULL)
{
x=*(location->data);
return success;
}
else
return not_present;
}