Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. Inserting items in a non birany tree

Inserting items in a non birany tree

Scheduled Pinned Locked Moved IT & Infrastructure
tutorialquestionalgorithmsdata-structureshelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    llp00na
    wrote on last edited by
    #1

    Dear All, I would be grateful if any of you guys could guide me on this problem which has been driving me nuts and i am about to give up. I have constructed a none binary tree (in which a node might have more than 2 children). Now i want to insert an item at a specific level (N). To do that, i would first need to check on the other nodes which belong to the same level (depth), if the item does not exist, only then the new item should be created. My problem is as follows: how do i go through the nodes which belong to level N (i.e node of the same depth) ? I would be grateful if someone can provide some pseudo code / algorithm on how to do that. Please bear in mind that this is a none binary tree. lets assume node is the root of the tree, the children are stored in an arraylist of nodes. public void check(Node node, int level){ }

    llp00na

    P D 2 Replies Last reply
    0
    • L llp00na

      Dear All, I would be grateful if any of you guys could guide me on this problem which has been driving me nuts and i am about to give up. I have constructed a none binary tree (in which a node might have more than 2 children). Now i want to insert an item at a specific level (N). To do that, i would first need to check on the other nodes which belong to the same level (depth), if the item does not exist, only then the new item should be created. My problem is as follows: how do i go through the nodes which belong to level N (i.e node of the same depth) ? I would be grateful if someone can provide some pseudo code / algorithm on how to do that. Please bear in mind that this is a none binary tree. lets assume node is the root of the tree, the children are stored in an arraylist of nodes. public void check(Node node, int level){ }

      llp00na

      P Offline
      P Offline
      Paddy Boyd
      wrote on last edited by
      #2

      public bool check(Node node, int level){

      bool canInsert;

      if (node.Level == level)
      {
      // do some checking, return false if not ok to insert.
      }
      else
      {
      if (canInsert) // check to see can still insert
      {
      foreach (childNode in node) { call check(childNode, level); }
      }
      }

      }

      1 Reply Last reply
      0
      • L llp00na

        Dear All, I would be grateful if any of you guys could guide me on this problem which has been driving me nuts and i am about to give up. I have constructed a none binary tree (in which a node might have more than 2 children). Now i want to insert an item at a specific level (N). To do that, i would first need to check on the other nodes which belong to the same level (depth), if the item does not exist, only then the new item should be created. My problem is as follows: how do i go through the nodes which belong to level N (i.e node of the same depth) ? I would be grateful if someone can provide some pseudo code / algorithm on how to do that. Please bear in mind that this is a none binary tree. lets assume node is the root of the tree, the children are stored in an arraylist of nodes. public void check(Node node, int level){ }

        llp00na

        D Offline
        D Offline
        DavidNohejl
        wrote on last edited by
        #3

        llp00na wrote:

        how do i go through the nodes which belong to level N (i.e node of the same depth) ?

        BFS


        "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups