Creating nested data structure

Welcome Forums General PowerShell Q&A Creating nested data structure

Viewing 3 reply threads
  • Author
    Posts
    • #284242
      Participant
      Topics: 1
      Replies: 0
      Points: 6
      Rank: Member

      Hi all

      I have a string like ‘A/B/C’ that I’m trying to get into a nested structure like the following:

      I thought this would be pretty straightforward using recursion, but only the top-level hashtable (“A”) gets added to $bar…

      Any ideas? Must be some issue with passing by ref the deeper array?

      Note I have an array of strings like ‘A/B/C’ (e.g. ‘A/B/D’, ‘D/E/F) to add to the structure, but that should be easy once I get past this first issue…

      • This topic was modified 1 week, 6 days ago by bgrossman.
      • This topic was modified 1 week, 6 days ago by grokkit.
      • This topic was modified 1 week, 6 days ago by grokkit. Reason: gist display
    • #284254
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,986
      Helping Hand
      Rank: Community Hero

      Here is one way, build it backwards:

    • #284272
      Participant
      Topics: 5
      Replies: 249
      Points: 985
      Helping Hand
      Rank: Major Contributor

      Wow this was a fun exercise.  Haven’t messed with recursion much since my freshman year at college.  I created a recursive function that will create the data structure you want.

       

    • #284890
      Participant
      Topics: 1
      Replies: 95
      Points: 435
      Helping Hand
      Rank: Contributor

      I like using a Stack object for this exercise:

Viewing 3 reply threads
  • You must be logged in to reply to this topic.