Re: [algogeeks] Re: t9 dictionary

2013-06-09 Thread sourabh jain
hi this is my java implementation of trie with 26 keys.

public class Trie {
public Trie [] childs;
char data;
 boolean isEnd;
TreeSetString ts;
String possiblity;
 public Trie(){
childs=new Trie[26];
isEnd=false;
 ts=new TreeSetString();
}
public void add(String s){
 char ar[]=s.toLowerCase().toCharArray();
 StringBuffer sb=new StringBuffer();
 for(int i=0;iar.length;i++){
if('a'=ar[i]  'z'=ar[i]){
sb.append(ar[i]);
 }else if('A'=ar[i]  'Z'=ar[i]){
sb.append((char)('a'+ar[i]-'A'));
 }
}
ar=sb.toString().toCharArray();
if(ar.length1) return;
 ts.add(sb.toString());
_add(this,ar,0);
 }
public void _add(Trie root,char ar[],int index){
if(root.childs[ar[index]-'a']==null){
 root.childs[ar[index]-'a']=new Trie();
root.childs[ar[index]-'a'].data=ar[index];
 }
 if(ar.length-1==index){
root.childs[ar[index]-'a'].isEnd=true;
 root.childs[ar[index]-'a'].possiblity=new String(ar);
return;
}
 _add(root.childs[ar[index]-'a'],ar,index+1);
}
public boolean search(String s){
 if(s.indexOf( )!=-1){ System.out.println(s); return;}
char ar[]=s.toLowerCase().toCharArray();
 if( _search(this,ar,0)){
return true;
}
return false;
 }
 public boolean _search(Trie root,char ar[],int index){
 if(index = ar.length) return false;
if(root==null) return false;
return (index==ar.length-1  root.childs[ar[index]-'a']!=null 
root.childs[ar[index]-'a'].isEnd)? true:
_search(root.childs[ar[index]-'a'],ar,index+1);
 }
}


On Mon, Jun 3, 2013 at 11:22 PM, rahul sharma rahul23111...@gmail.comwrote:

 Can i implement by trie which is having structure as 9 pointers for 9
 digits..like if it comes 4663...i will make a path 4663 from root to leaf
 and in end i will have a linked list to store dataany more optimized
 solution anyone having???plz suggest


 On Thu, May 30, 2013 at 2:37 AM, rahul sharma rahul23111...@gmail.comwrote:

 how to implement with trie.???is trie the best way..plz provide me raw
 algo to start with,


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.






-- 
Regards,
Sourabh Kumar Jain
+91-8971547841

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




[algogeeks] Re: t9 dictionary

2013-06-05 Thread rahul sharma
Can i implement by trie which is having structure as 9 pointers for 9
digits..like if it comes 4663...i will make a path 4663 from root to leaf
and in end i will have a linked list to store dataany more optimized
solution anyone having???plz suggest


On Thu, May 30, 2013 at 2:37 AM, rahul sharma rahul23111...@gmail.comwrote:

 how to implement with trie.???is trie the best way..plz provide me raw
 algo to start with,


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.