Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8386601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:59:08+00:00 2026-06-09T17:59:08+00:00

Hello suppose you have ordinary unix path tree as input (as string). root 0

  • 0

Hello suppose you have ordinary unix path tree as input (as string).

root 0
root/file1.txt 1
root/file2.txt 2
root/folder1 3
root/folder1/file3.txt 4
root/folder1/file4.txt 5
e.t.c.

What is the better way to convert this string to tree data structure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:59:10+00:00Added an answer on June 9, 2026 at 5:59 pm

    Now i use simple tree representation, created by myself

    template<typename T>
    class TreeNode
    {
    public:
        TreeNode() {};
    
        TreeNode(T)
        {
            value = T;
        }
    
        TreeNode(const T& value)
            : Value(value)
        {
        }
    
        T Value;
        vector<TreeNode<T>*> Children;
    };
    

    I don’t really understand Gir’s algorithm (posted above). But i suppose the solution must be the following:

    1. Get a root node, set depth_level = 0
    3. set support_node = root_node
    4. for each path line
    5.     determine the quantity of slashes "/", key and file(folder) name
    
    so for example in string root/folder1/file4.txt 5, num of slashes = 2 filename = file4.txt, key = 5
           create current_node
    6.     if num_of_slashes == level + 2
    7.          set support_node = current_node
    8.     if num_of_slashes == level + 1
    9.          add children to support_node
    10.    And after that we must remember all ancestors,  going down to leaves. Cuz we can  return to any ancestor.
    

    For me this algorithm seems to be really complicated. I don’t understand algorithm, posted above, maybe it is possible to clarify this question? Maybe the structure i use to store the tree isn’t the best one?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this code: String encoding = UTF-16; String text = [Hello StackOverflow];
In perl suppose I have a string like 'hello\tworld\n' , and what I want
suppose I have a simple container which have three element: <div> <span>hello world</span> <input
Suppose file1 looks like this: bye bye hello thank you And file2 looks like
Suppose I have String str=Hello $everybody$. How $are$ you $all$; From above string, I
Suppose you have the following string: Hello... how are you!!?? I'm bored!! I want
Suppose I have a String, Hello World. I want to change the style of
Suppose I have defined a function: def hello(name:String, words:String) = println(Hello! + name +
Suppose we have string like this: Hello, my\n name is Michael. How can I
Suppose you have a dictionary that contains valid words. Given an input string with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.