Trie data structure using Java

No need to see the code...
i properly documented for easy understanding....
plz dont hesistate to go through code..
class treenode{                //tree node structre....
   char ch;
   treenode child;
   treenode sibling;
    treenode(){                              //constructore
        child=null;
        sibling=null;
        ch='$';
public class trie{
   treenode root=new node();             //defining root node
   public void main(String s{}){
         string s1[]={"hi","subbu","how r u"};
        for(int i=0;i<s1.lengh();i++){
                    storetrie(s1,root.sibling); //calling trie function
printtrie(temp.sibling);
printtrie(treenode temp){                             //printing trie
if(temp!=null){
System.out.print(temp.ch);
printtrie(temp.child):
printtrie(temp.sibling);
public void storetrie(String str,treenode temp){       //constructing trie
if(temp==null){             // if data is dissimilar
int i=0,k=str.length(); //storing string length
temp=new treenode();
while(i<k){                 //add string to trie one charater by character
temp.ch=str.charAt(0);
str=str.substring(1); //forwarding string
System.out.print(temp.ch);
temp.sibling=null;
temp.child=new treenode(); //for next child
temp=temp.child; //moving to child
i++;
if(root.sibling==null){                  //errorrrrrrrrrrrrr        this condition should fail......but it is satisfying...........objects are passed through refences...it should change i think...
System.out.println("root is null..");
else{
if(str.charAt(0)==temp.ch){
storetrie(str.substring(1),temp.child);
else{
storetrie(str,temp.sibling);

this is my actual code...
this code will take some folder address on hard disk
filenames stored in folders iam storing in trie
trie is not printing...
my code is not storing filenames in trie ...what could be the problem
import java.io.*;
import java.io.File;
class treenode{
      char ch;
      treenode sibling;
      treenode child;
      public treenode(){
           sibling=null;
           child=null;
           ch='$';
public class finalone{
       treenode root=new treenode();       //root node definition
       public static void main(String s[]){
              finalone x=new finalone();
              File f=new File("G:/Papers");      //folder address
              x.store(f);
              System.out.println();
              x.printtrie1();                              //calling printing trie function
        public void printtrie1(){
           printtrie(root.sibling);
        public void store(File f){
               if(f.isDirectory()){
                      File str[]=f.listFiles();
                      String strname[]=f.list();
                      for(int i=0;i<str.length;i++){
                            storetrie(strname,root.sibling);
if(i==0)break;
// System.out.println(strname[i]);
// store(str[i]);
else{
// System.out.println(f);
public void printtrie(treenode temp){
if(temp!=null){
System.out.print(temp.ch);
printtrie(temp.child);
System.out.println();
printtrie(temp.sibling);
public void storetrie(String str,treenode temp){
if(temp==null){
int i=0,k=str.length();
temp=new treenode();
while(i<k){
if(str==null){
return;
temp.ch=str.charAt(0);
str=str.substring(1);
System.out.print(temp.ch);
temp.sibling=null;
temp.child=new treenode();
temp=temp.child;
i++;
//temp=null;
if(root.sibling==null){
System.out.println("root is null..");
else{
if(str.charAt(0)==temp.ch){
storetrie(str.substring(1),temp.child);
else{
storetrie(str,temp.sibling);

Similar Messages

  • How to get the values from struct data type using java code..?

    Hi ,
    I am newer to java.
    we are using oracle database.
    How to get the data from struct data type using java code.
    Thanks in Advance.
    Regards,
    kumar

    Hi Rajeev,
    To retrieve a FilterContainer you will need to traverse the report structure:
    ReportStructure boReportStructure = boDocumentInstance.getStructure();
    ReportContainer boReportContainer = (ReportContainer) boReportStructure.getReportElement(0);
    FilterContainer boFilterContainer = null;
    if (boReportContainer.hasFilter()) {
         boFilterContainer = boReportContainer.getFilter();
    } else {
         boFilterContainer = boReportContainer.createFilter(LogicalOperator.AND);
    Calling boDocumentInstance.getStructure() will retrieve the entire structure for the document.
    Calling boReportStructure.getReportElement(0) will retrieve the structure for the first report of the document.
    Hope this helps.
    Regards,
    Dan

  • Copying complete directory structure using java.io.File

    Is there a solution to problem when you want to copy a complete directory structure using java.io.File class as you can copy when using FTP connection.

    Is there a solution to problem when you want to copy
    a complete directory structure using java.io.File
    class as you can copy when using FTP connection.FTP does not have a command to transfer all the files in a directory. FTP clients implement this by invoking single file transfer for each file in a directory.

  • What Tree Data Structures does Java Include?

    Hello,
    I have been reading about several tree data structures like a binary search tree, self-balancing bst, minimum spanning tree, red-black tree, AVL tree, etc... Are there data structures in Java represent the various trees, or is implementation of the ds left to user?
    Eric

    "Java" can be termed the "Java Language". The language does not have trees.
    In more general usage "Java" can refer to a standard, desktop, delivered VM which includes the standard Java API. The types that you are asking about would be found in the following package.
    [http://java.sun.com/javase/6/docs/api/java/util/package-summary.html]
    "Java" could also refer to any other commonly available implementations. In that case probably anything that can be implemented has been implemented somewhere. Googling works.

  • Trees Data Structures in Java

    Hi all !
    Currently I�m developing a Java software that requires a Tree data structure. Searching through Java API I�ve found classes like TreeMap and TreeSet, but although these classes seens to use tree structure behind what they really provide are linear data structure, not a tree data structure. My question is if there is a public and free Java tree data structure that permits to do activities such as:
    - Search for a particular node (efficiently)
    - Insert children to any node
    - Maintain one Object in each node
    Simple like this ! It must have something like this in Java, but I just can�t find it and I�m just too lazy to implement it :) ! Anyone can help me ?
    Thanks in advance !

    Mel,
    I�ve seen javax.swing.tree.TreeModel and its seens more like an implementation of Control in swing MVC (Model Vision Control) swing paradigm for JTree. It has listeners generated for manipulation events for example. It uses javax.swing.tree.DefaultMutableTreeNode for its nodes, and maybe I could use this class for the nodes of my tree since it has many useful operations. However still I miss a node searching operation that this class doesn�t have.
    Yes my problem is a simple Tree, but it is simple now and it might become much more complex, demanding more operations on the tree and specially efficient searching algorithms. Thats why I�m looking for a complete solution and I prefer something that is already done and well tested :) !
    Thanks for your tip !

  • Crystal Reports data connection using Java beans

    Hi
    My name is Bach Ong, i'm currently perform re-configuring Crystal reports 2008 to connect via
    Java bean to Jboss server, this uses look up service on JBoss server. The connection is using Connect
    look up using the properties:
    java.naming.provider.url=jnp://emgsydapp121:10499
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    for file CRConfig.xml i put as follows:
    <JDBCURL></JDBCURL>
    <JDBCClassName></JDBCClassName>
    <JDBCUserName></JDBCUserName>
    <JNDIURL>jnp://emgsydapp121:10499</JNDIURL>
    <JNDIConnectionFactory>org.jnp.interfaces.NamingContextFactor
    y</JNDIConnectionFactory>
    <JNDIInitContext>/</JNDIInitContext>
    <JNDIUserName></JNDIUserName>
    Can you advise us if this step is correct, and is there any
    documentation that can guide us to right direction.
    for Java testing in Eclipse using remote call class it is working suing the following code:
            Properties p = new Properties();
            p.put(Context.INITIAL_CONTEXT_FACTORY,
            "org.jnp.interfaces.NamingContextFactory");
            p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
            p.put(Context.PROVIDER_URL, "jnp://emgsydapp121:10499");
             InitialContext ctx = new InitialContext(p);
      Date asAtDate = CrystalUtils.convertToDate("2014-01-01", CrystalUtils.relativeToToday(0), false);
         String asxCode = "BHP";
         ClosingPricesReportRequest criteria = new ClosingPricesReportRequest(asAtDate, asxCode);
         InitialContext context = new InitialContext(p);
         ClosingPricesReportService ejb = (ClosingPricesReportService) context.lookup(ClosingPricesReportService.REMOTE_JNDI);
         ClosingPricesReport report = ejb.createMTMClosingPriceReport(criteria);
         System.out.println(report.getClosingPrices()[0].getClosingPrice());
         testval = report.getClosingPrices()[0].getClosingPrice().toString();
         System.out.println(testval);
    when i run the tes code the results as follow:
    10:49:45,244 DEBUG [SecurityAssociation ] Using ThreadLocal: false
    10:49:45,338 DEBUG [MicroSocketClientInvoker ] SocketClientInvoker[709446e4, socket://emgsydapp121:10473] constructed
    10:49:45,338 DEBUG [MicroRemoteClientInvoker ] SocketClientInvoker[709446e4, socket://emgsydapp121:10473] connecting
    10:49:45,338 DEBUG [MicroSocketClientInvoker ] Creating semaphore with size 50
    10:49:45,338 DEBUG [MicroRemoteClientInvoker ] SocketClientInvoker[709446e4, socket://emgsydapp121:10473] connected
    10:49:45,369 DEBUG [ClientSocketWrapper ] reset timeout: 0
    10:49:45,650 DEBUG [InvokerRegistry ] removed SocketClientInvoker[709446e4, socket://emgsydapp121:10473] from registry
    10:49:45,650 DEBUG [MicroSocketClientInvoker ] SocketClientInvoker[709446e4, socket://emgsydapp121:10473] disconnecting ...
    10:49:45,650 DEBUG [SocketWrapper ] ClientSocketWrapper[Socket[addr=/10.137.2.40,port=10473,localport=64150].2cba5bdb] closing
    37.99000000000000198951966012828052043914794921875
    37.99000000000000198951966012828052043914794921875
    Can anyone assist me in convert the above settings to get access by Crystal reports.
    My attemp current are below:
    public class CFDClosingPricesRpt extends CrystalReport {    
        //Constructor
        public CFDClosingPricesRpt(){
            super(ClosingPriceBean.INSTANCE);
         * Returns the ResultSet for this report to Crystal.
         * @param asxCode
         * @param asAtDateString
         * @return
    public ResultSet getNewReport(String asxCode, String asAtDateString) {                     
         try {
             Properties p = new Properties();
             p.put(Context.INITIAL_CONTEXT_FACTORY,
             "org.jnp.interfaces.NamingContextFactory");
             p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
             p.put(Context.PROVIDER_URL, "jnp://emgsydapp121:10499");
             //InitialContext ctx = new InitialContext(p);
             clearCachedReportBeans();     
       Date asAtDate = CrystalUtils.convertToDate("2013-01-01", CrystalUtils.relativeToToday(0), false);
          asxCode = "BHP";
          ClosingPricesReportRequest criteria = new ClosingPricesReportRequest(asAtDate, asxCode);
          //ClosingPricesReportService ejb = (ClosingPricesReportService) ctx.lookup(ClosingPricesReportService.REMOTE_JNDI);
          ClosingPricesReportService ejb = (ClosingPricesReportService) ServiceLocator.getInstance().getService(ClosingPricesReportService.REMOTE_JNDI);           
          ClosingPricesReport report = ejb.createClosingPriceReport(criteria);
          // assemble Crystal-friendly DTO
          Collection closingPrices = Arrays.asList(report.getClosingPrices());
          for (Iterator iter = closingPrices.iterator(); iter.hasNext();) {
                    MBLXClosingPrice cp = (MBLXClosingPrice) iter.next();               
                    if (cp==null) continue;               
                    addReportBean(new ClosingPriceBean( report.getSuppliedDate(),
                                cp.getClosingPrice(),
                                cp.getAsxCode()));
      } catch (Throwable x) {     
          saveErrorMessage(x);
      return getAsResultSet();             
    Thanks
    Bach Ong

    Hi Don Thanks for the reply.
    I've was able to connect via Java beans and JNDI. But this one is going the JNDI of JBoss sever, which the JNDI already configure and working for Crystal reports v10.
    Bach

  • Need help on how to construct proper data structure using vector

    I have several data files need to be loaded to my application. The data file has only 2 columns: "mean" and "standard deviation". The data file is looking like following:
    mean standard deviation
    217.0 27.3
    312.1 31.5
    I used two vectors to store the mean data and standard deviation data.
    Vector meanVec = new Vector();
    Vector stdVec = new Vector();
    the file is loaded once a time. so how to make a vector of vector to store the data like a matrix?
    In another word, when multiple files need to be loaded, how can I keep track and store these data to display in two table (or files) which can display mean data from all the files and std from all files, like the following:
    table1 or file1
    mean1 mean2
    217.0 282.3
    table2 or file2
    std1 std2
    27.3 27.9
    Any suggestion is greatly appreciated!

    If your application doesn't require to keep track of which mean (or std.dev.) values come from which file, whatever you are doing is just fine.
    Use ArraList in place of Vector, as Vector being part of older collection framework is avoided in newer programs (as far as I know).
    While reading each file line by line in a loop, store the first value on each line in one list and the second value in the other. After reading all the files, you would have two lists containing the mean and std. dev. values.

  • Data communication using java

    Hi every one,
    I have a question.
    Can I achieve data transmission between computers using some individual defined address rather than the IP address?
    Is there a way possible to achieve this?
    Thank you
    Song

    Hi,
    No, I mean to achieve another communication protocol totally disregard the ip address of the computer.
    For example, I have a physical connection of the two computers and I define each computer a kind of address and I need they can transmit data to each other using the new type of address I defined
    Thank you
    Song

  • Need help in Data Structure in Java

    Design a FSA which accepts all strings over {a,b} which end in b, and in which every b (except for the last one) is immediately followed by two or more a's.
    Convert the following into a deterministic finite state automaton, using the subset construction algorithm.
    a,b
    \/ a b a
    --> 0 --> 1 --> 2 ---> 3
    State 3 is accepting.
    Describe (in English) the language which the regular expression (a|ba)* denotes.
    Using the techniques discussed in class, convert the regular expression in the previous problem to an FSA with epsilon transitions.
    Now convert the FSA from the previous problem to an equivalent FSA without epsilon transitions.
    I have to solve this problem .. can anyone help me out here?

    I have to solve this problem .. can anyone help me out
    here?Your code didn't show up in the post. Please re-post with code
    describing where you are having the problem.

  • How to parse ".dat" file using java?

    Hi experts/friends,
    I need to parse the ".dat" files such as "history.dat" of Firefox history and "index.dat" of IE history...
    I cannot able to parse those files.
    Can anyone suggest me or help me....

    Google ( [url http://www.google.com/search?q=firefox+history+file+format]firefox history file format )
    Google ( [url http://www.google.com/search?q=internet+explorer+history+file+format]internet explorer history file format )

  • Data Structures and Algorithms in java book

    Hi guys,
    I want to know a good book which is good for Data Structures and Algorithms in java. I am good at Core java but a beginner for Data Structures in Java. I am a little poor in Data Structures concepts.
    Following are the books I have found on the net. Could you help me the choose the best outta them.
    1. Data Structures and Algorithms in Java - Mitchell Waite
    2. Data Structures in Java - Sandra Anderson
    3. Fundamentals of OOP and Data Structures in Java - Richard Weiner & Lewis J. Pinson
    4. Object Oriented Data Structures Using Java - Nell Dale, Daniel T. Joyce, Chip Weems

    lieni wrote:
    I good data structures book doesn't have to be language-specific.Thx DrLazlo, my speachYes.
    The OP wrote:
    I have access to these books and dont know which one to start with.What I meant is that you shouldn't narrow your search to insist that the book you choose have "Java" in the title.

  • Request: DATA STRUCTURES files and examples

    please could you provide me some resources Data Structure using Java (NetBeans)..
    I hardly understood our instructor lessons..

    mark2k7 wrote:
    nonsense replies from nonsense people!! WTF!! Indeed. That's what everyone thought reading your question. Perhaps if you put a little more thought into asking specific, coherent questions you would get more useful answers.

  • Need a good Data Structure/ Algorithm

    I am working on a small problem that requires me to cache a large amount of key/value pairs of data. I must then do a lookup on the cache for a large number of words one after another until I find a word that is present as a Key and then quit.
    The cache is pretty large. About 600 - 1000 words as keys and ints as values.
    Is there an existing Data Structure in Java for this? If not, what type of data structure (B-tree etc) is best suited to cache such data and what algorithm should be used for lookup?

    The lookup for hashmap is efficient for very large maps up to the amount of memory you have. If you tune the load factor you can minimise the impact of having very large tables.
    Another option is to have a fixed array of HashMaps. You can use the hashcode (or your own) to put the key, value into the HashMap. I am not sure if this is actaully any faster, as I believe one is enough, but if you have concern this is what you can do.

  • Creating database using java

    hey i Have a question can i write a code to write a database and make my own using data structures using no jdbc no sql or oracle or anything
    can anybody suggest me the possible steps n logicthat may be possible

    By "database" people most often mean a relational database, but yes, a database can be any store of data.
    As to how to build it - well that rather depends upon what you want to store, what your requirements are for retrieving it, how fast you want to get at it, and so on.
    At it's simplest you could put the data into one of the Collection classes and write it out to disk using the Serialization API. Links follow:
    http://java.sun.com/docs/books/tutorial/collections/index.html
    http://java.sun.com/developer/technicalArticles/Programming/serialization/

  • Data Structure Needed

    *** PLEASE DO NOT REPLY TO THIS POSTING UNLESS
    *** YOU KNOW EXACTLY WHAT I AM TALKING ABOUT
    *** AND HAVE SOLUTION AT THE READY.
    *** NO SWING TREE FYIs PLEASE...doesn't apply.
    *** NO UI JAVASCRIPTS .. I HAVE THOSE.
    I need a properly constructed multiway
    (m-way, general, n-ary, etc.) data structure
    implementation that uses non-ui
    dependent/associated classes. This is know as the
    first child/next sibling data structure used in
    Filesystems (similiar to a BTree).
    I am using many delimited strings, similiar to a
    directory/file structure path but the string is a
    software project hierarchy.
    [a string is structured like this]
    root|branch|...|branch|leaf
    [Process]
    1) the strings are fetched from DB by servlet.
    2) servlet feeds strings into data structure
    to eliminate duplicates and place in proper location.
    3) servlet uses contents of data structure to
    construct links that are coupled with the infamous
    ui-tree script.
    If you know your data structures and have an implementation
    that won't take me 6 days to modify for it to work I would
    appreciate your assistance. I am creating on my own as we
    speak but one from a more experienced java programmer would
    be better.
    Thank You,
    Kevin

    Sounds like one hell of a frustrated programmer over there - all those capitals an'all..
    If I understand you correctly, I don't think you'd take six days to implement this; just split your string by the separator;
    String[] split(String path, char sep, char esc) {
      String[] result = new String[0];
      int o = 0;
      int i; for (i=0; i<path.length(); ++i) {
        char c = path.charAt(i);
        if (c == esc) {
          ++i;
          continue;
        if (c == sep) {
          String substring = path.substring(o, i);
          String[] newresult = new String[result.length+1];
          System.arraycopy(result, 0, newresult, 0, result.length);
          newresult[result.length] = substring;
          result = newresult;
          o = i+1;
    }Then have a java.util.Hashtable as root, with all names in it pointers to either more Hashtables (nodes), or Strings (leaves). If it really does not get anymore complex than that (data associated with leaves, for example), you don't really have to use anything more complex than 'instanceof' here.
    Then start looping over all your String[] split paths, retrieve all nodes, if it's a String and you have a child for it, then convert it to a Hashtable, it it's a Hashtable trod along, if it isn't there create a String (unless you know you have an extra child, in which case you create a Hashtable).
    When you're ready to retrieve, just enumerate your root Hashtable, casting to String all the keys, examining all the values; if they are Hashtable, then recurse. If they're Strings, do your Thing (TM).

Maybe you are looking for

  • No longer getting internet over E2500

    My E2500 was working great for the past 3 months, and now it seems to be broken since I cannot access the internet anymore. I can connect to the router via wireless or wired at 192.168.1.1 and play with all the settings. On the status page, I have en

  • Outlook Express and Netscape/Default e-mail account

    I have recently replaced my Internet Explorer with Netscape 7.02. When I send an e-mail from a website on Netscape, it prompts me to set up a new account to send the e-mail. IE always launched Outlook Express when I sent an e-mail from a website. Out

  • Saving font's in Photo Shop

    I'm making a book with large full bleed illustrations on each page. For ease of use I would like to use regular photoshop fonts. If I flatten and save my pages as Tiff files will it be the same as outlining fonts in Illustrator? In other words I won'

  • How to import xls file to BPA11gR1

    I got business flow from customer,one xml and one xls file. I imported xml file as following: New a database. Run BPA(11gR1) and open above database. Right-click on the group and select Evaluate/Start macro. The Macro Wizard opens. Select the "Import

  • How can I get FF to print my crossword in greyscale?

    I belong to The Times crossword website. when a crossword is accessed there are two buttons on the page: print in black, print in grey. If you click on print in grey the crossword turns grey, and it appears grey on the page and in print preview. Howe