CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2017
    Posts
    2

    Question How properly implement search functionality?

    Good Day to all Java Gurus!

    Consider a tree data structure implemented by the following Java class:

    public class Tree {
    private List<Tree> leaves = new LinkedList<Tree>();
    private Tree parent = null;
    private String data;

    public Tree(String data, Tree parent) {
    this.data = data;
    this.parent = parent;
    }
    }

    I am trying to figure out how to implement search functionality using a method with the footprint: Tree firstMatch(Tree, Regex). This method takes a tree, searches that tree for leaves/branches in which the data matches the given regex expression and returns the first branch/leaf (another Tree object) that matches. I need to implement two different search algorithms: a Depth-First Search (DFS), and another search algorithm (anything better then DFS?).

    Thank you for help

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: How properly implement search functionality?

    What have you tried?
    Norm

  3. #3
    Join Date
    Jan 2017
    Posts
    2

    Re: How properly implement search functionality?

    Hi Norm, thank you for response,

    I know JS, PHP, but total Noob to Java

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: How properly implement search functionality?

    Ok, Time to start learning.
    Do you have the steps for algorithms you want to implement in java?

    Can you list the steps needed to build the tree to be searched? Start with that. You'll need the tree for the searches.

    Be sure to wrap all posted code in code tags.
    Norm

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: How properly implement search functionality?

    a Depth-First Search (DFS), and another search algorithm (anything better then DFS?
    Another common search algorithm is Breadth-First-Search. See https://en.wikipedia.org/wiki/Breadth-first_search
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured