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. General Programming
  3. Managed C++/CLI
  4. Can Someone please convert this from C++ to C? Topic : "Placement of Signal Boosters Using Tree Data Structures."

Can Someone please convert this from C++ to C? Topic : "Placement of Signal Boosters Using Tree Data Structures."

Scheduled Pinned Locked Moved Managed C++/CLI
c++data-structuresquestion
2 Posts 2 Posters 7 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.
  • M Offline
    M Offline
    ManojMaheshPatil
    wrote on last edited by
    #1

    // place signal boosters #include #include "booster.h" #include "linkedBinaryTree.h" using namespace std; int tolerance = 3; void placeBoosters(binaryTreeNode *x) {// Compute degradation at *x. Place booster // here if degradation exceeds tolerance. x->element.degradeToLeaf = 0; // initialize degradation at x // compute degradation from left subtree of x and // place a booster at the left child of x if needed binaryTreeNode *y = x->leftChild; if (y != NULL) {// x has a nonempty left subtree int degradation = y->element.degradeToLeaf + y->element.degradeFromParent; if (degradation > tolerance) {// place a booster at y y->element.boosterHere = true; x->element.degradeToLeaf = y->element.degradeFromParent; } else // no booster needed at y x->element.degradeToLeaf = degradation; } // compute degradation from right subtree of x and // place a booster at the right child of x if needed y = x->rightChild; if (y != NULL) {// x has a nonempty right subtree int degradation = y->element.degradeToLeaf + y->element.degradeFromParent; if (degradation > tolerance) {// place booster at y y->element.boosterHere = true; degradation = y->element.degradeFromParent; } if (x->element.degradeToLeaf < degradation) x->element.degradeToLeaf = degradation; } } int main(void) { booster a, b; a.degradeFromParent = 2; a.degradeToLeaf =0; a.boosterHere = 0; b.degradeFromParent=1; b.degradeToLeaf=0; b.boosterHere = 0; linkedBinaryTree t, u, v, w, x, y; u.makeTree(a,x,x); v.makeTree(b,u,x); u.makeTree(a,x,x); w.makeTree(a,u,x); b.degradeFromParent=3; u.makeTree(b,v,w); v.makeTree(a,x,x); b.degradeFromParent=3; w.makeTree(b,x,x); y.makeTree(a,v,w); w.makeTree(a,x,x); t.makeTree(b,y,w); b.degradeFromParent=0; v.makeTree(b,t,u); v.postOrder(placeBoosters); v.postOrderOutput(); return 0; }

    D 1 Reply Last reply
    0
    • M ManojMaheshPatil

      // place signal boosters #include #include "booster.h" #include "linkedBinaryTree.h" using namespace std; int tolerance = 3; void placeBoosters(binaryTreeNode *x) {// Compute degradation at *x. Place booster // here if degradation exceeds tolerance. x->element.degradeToLeaf = 0; // initialize degradation at x // compute degradation from left subtree of x and // place a booster at the left child of x if needed binaryTreeNode *y = x->leftChild; if (y != NULL) {// x has a nonempty left subtree int degradation = y->element.degradeToLeaf + y->element.degradeFromParent; if (degradation > tolerance) {// place a booster at y y->element.boosterHere = true; x->element.degradeToLeaf = y->element.degradeFromParent; } else // no booster needed at y x->element.degradeToLeaf = degradation; } // compute degradation from right subtree of x and // place a booster at the right child of x if needed y = x->rightChild; if (y != NULL) {// x has a nonempty right subtree int degradation = y->element.degradeToLeaf + y->element.degradeFromParent; if (degradation > tolerance) {// place booster at y y->element.boosterHere = true; degradation = y->element.degradeFromParent; } if (x->element.degradeToLeaf < degradation) x->element.degradeToLeaf = degradation; } } int main(void) { booster a, b; a.degradeFromParent = 2; a.degradeToLeaf =0; a.boosterHere = 0; b.degradeFromParent=1; b.degradeToLeaf=0; b.boosterHere = 0; linkedBinaryTree t, u, v, w, x, y; u.makeTree(a,x,x); v.makeTree(b,u,x); u.makeTree(a,x,x); w.makeTree(a,u,x); b.degradeFromParent=3; u.makeTree(b,v,w); v.makeTree(a,x,x); b.degradeFromParent=3; w.makeTree(b,x,x); y.makeTree(a,v,w); w.makeTree(a,x,x); t.makeTree(b,y,w); b.degradeFromParent=0; v.makeTree(b,t,u); v.postOrder(placeBoosters); v.postOrderOutput(); return 0; }

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      We're not here to do your job for you.

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      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