C :: Recursion For Finding Distance Between Root And Leaf?

Jun 19, 2013

I wrote the following recursion for finding the distance between a root and a leaf, but am not quite sure how to make it work.

Code:
int calc_depth(Node* tree, Node* zero) {
if (!tree)
return 0;
if (zero->right || zero->left == tree)
return 1;
return (zero->right ? calc_depth(tree, zero->right) : calc_depth(tree, zero->left));
}

View 14 Replies


ADVERTISEMENT

C++ :: BST - Any Way To Travel From A Leaf To The Root

Apr 30, 2014

Any way to travel from a leaf to the root. For example I search the tree to find the leaf i want and then trace/record the path back to the root.

View 2 Replies View Related

C++ :: Binary Search Tree (Distance From Node To Root)

Jul 28, 2014

I have my tree, and I need to find the number in the tree (given by the user) and get the distance between the node found and the root.

What I've done so far is this, but I don't think it's correct.

void BinarySearchTree::find() {
system("cls");
BinarySearchTree b;
int num;
tree_node* cur;

[Code] ....

I founded the node, but I don't know how to determine the distance.

View 3 Replies View Related

C++ :: Finding The Root Of Equation Using Secant Method

Feb 8, 2014

I want to find the root of an equation f(x) by using the secant method [URL] .....

#include <math.h>
#include <iostream>
using namespace std;
//Define function f(x)
double f(double x, double a, double b) {
return sin((a*x)/(1+x*x))*atan(b*x)+atan(x);

[Code] ....

1) Do I have to keep the function f and RootFinderSMNew in different cpp files?

2) When compiling I get the following errors:

1>------ Build started: Project: Assignment2.1, Configuration: Debug Win32 ------
1> Find Roots Secant method.cpp

[Code] .....

What am I doing wrong ?

View 1 Replies View Related

C :: Function Macro For Finding Square Root Of A Number

Jul 13, 2014

How to write a function macro in C for finding the sqrt of a number?

View 2 Replies View Related

C++ :: QuadTree - Should Non-Leaf Nodes Contain Points

Oct 25, 2013

I'm implementing a quad tree for an assignment, and I'm not sure if every node should contain a list of pointers to every Point in its sub tree (implying the root node will contain all Points), or if only leaf nodes should contain the Points.

View 4 Replies View Related

C :: How To Do Euclidian Distance

May 22, 2013

how would i go about writing up an equation for euclidian distance using c language. I am quite unfamiliar with the syntax's involved using squared and square roots.the equation for euclidian distance is: square root((Xv -Xu)^2 + (Yv-Yu)^2 +(Zv-Zu)^2)

The variables Xv, Yv and Zv represent the equation of vector 1 and then variables Xu, Yu and Zu represent the equation of vector 2. I have already put these into my program and i just need to know how to write that equation up there into the text file so that it works.

View 4 Replies View Related

C++ :: Square Root Of Number

Dec 9, 2013

i have written a function that gives me the square root of a number. Yes i know there is already a function in <cmath> that gives square roots but i thought it would be pretty challenging (and therefore fun) to try writing one on my own. I wrote my code while i was in school, listening to my Irish teacher ramble on and on about useless shit, so it's probably not the best possible way of finding the square root of a number.

double msqrt(double x) {
double adder=1;
double y = x;
for(int a=0; ; a++) {
if(y*y > x) y = y/2;
if(y*y <= x) break;

[code]....

View 6 Replies View Related

C++ :: Splaying Elements To The Root

Dec 13, 2014

I am having some difficulties splaying this element to the root.. Considering i have this splay tree .

0

1

2

3

4

What are the steps to get it 4 to the root?

View 1 Replies View Related

C++ :: BST Comparing Parents To The Root

Mar 18, 2014

Lets say for example I have a BST that is sorted by char names, using strcmp. IF greater than 0 go right else go left.

I.E (this is just an example, they are not inserted correctly)

cat
/
dog buffalo
/ /
fish mouse zebra snake

I wanted to make a copy of this BST IF the length of the nodes are greater than the root, how would I approach this? I kinda started on this but I'm not sure if I'm making this more difficult than it should be.

void BST::copygreater(node * root, node *& dest, int & holder) {
if(!root) {
dest = NULL;
return;
}

holder = strlen(root->name) + 1; //Don't know about this? If we do a recursive call then the value would change every call?

[Code] ......

View 2 Replies View Related

C++ :: Manhattan Distance Between Two Vectors

Mar 25, 2014

I can't figure out the error in this code; it compiles but returns rubbish.

serge
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>

[Code] ......

View 7 Replies View Related

C++ :: Distance Between 2 Points Equation

Apr 14, 2013

Write a program that creates the output shown in the Output Layout section below. The program should create 2 points with x and y coordinates as integers, prompt the user to input the x and y values for one of the points and randomly set the other (-99 to 99 range) and output the length of the radius line segment and the area of the circle that radius defines. The program should then end. Include an SDM for the program and any other appropriate documentation.

Special Calculations:
Distance between 2 points equation:
√((p0x – p1x)2 + (p0y – p1y)2) (This requires use of the math library)

Output Layout: (bold text represents user input)

Please enter the location of your first point.
Enter a value from -99 to 99 for your x coordinate: -2
Enter a value from -99 to 99 for your y coordinate: 17

The location of your second randomly set point.
Your x coordinate: 45
Your y coordinate: -89

The length of the radius line segment from point one to point two is 115.
The area of the circle with a radius of 115 is 41546.33.

Other:

int pAx;
int pAy;
int pBx;
int pBy;

View 3 Replies View Related

C++ :: Calculate Distance Between Two Points

May 15, 2014

It ougth to calculate the distance between two point (p1,p2)

"main.cpp"
#include "distancia.h"
void main () {
Point p1,p2;

[code]....

View 4 Replies View Related

C++ :: Closest Distance 2D Points?

Oct 29, 2014

In the following code I don't understand why am I splitting the y left and y right.

(closest distance between 2 points in 2D)

Am I splitting the y left and y right so that I can concatenate them afterwards and then build the strip,only according to these concatenated halves ?

PS : Finding the min. distance between sorted x right and x left works fine , only problem is with the strip.

#ifndef CLOSESTPAIR_H_
#define CLOSESTPAIR_H_
#include <float.h>
#include <math.h>
typedef struct Point2D {
double x;
double y;

[code].....

View 4 Replies View Related

C++ :: Null Root Binary Tree

May 19, 2013

I got problem in binary tree code. below is my code. When i select pre, post or inorder, the .exe is not responding.. Since in my binary tree theres no roots yet.. who do i solve it? It need condition or what?

View 1 Replies View Related

C++ :: Parse The Root Directory Of FAT32?

Dec 27, 2013

I'm trying to parse the root directory of FAT32 in order to get a dir list in the root folder.

So I need to go over all the directory entries in the root directory and parse them.

My problem is that I don't know when to stop the iteration - How to get the size of the root directory?

I noticed that there is a byte in the boot sector - the number of the entries in the root - but in FAT32 the value is always 0, So how can i get the size of the directory?

View 1 Replies View Related

C++ :: Relation Between Local Position And Distance

Feb 21, 2014

i have two point P1 and P2 where i want to move P1 and P2 with keeping the distance and the position of the P2 relative to P1 i thought that when i keep the distance between the two point that involve keep in the same time the local position of P2 but when tested it does not work initial position of P1=(10.0f, 00.0f, 00.0f) initila position of P2 relative to p1 =(50,10,-8) we can get the global position of p2 ----- final position of P1 =(50,10,-8) final position of P2 in the world space =(40.31,8.06,-6.45) then we calculate the distance before and after we found that there are equal but when we calculate the position of p2 relative to p1 after and before we found that there are not equal.

how i can keep the local position and distance ?

View 14 Replies View Related

C :: Calculating Distance Between Two Points (x And Y Vars)

Feb 23, 2013

As homework we were assigned to enter the following code to calculate the distance between two points on the x and y plane. The program should ask the user to enter two points then should calculate the distance between two points and print the distance on the screen.

My program will compile correctly but when attempting to run the actual program it doesnt do anything and some how completely skips over my main function...

Code:

#include <stdio.h>
#include <math.h>
struct point {
float x;
float y;

[Code] ....

View 2 Replies View Related

C++ :: Display A Table With Seconds And Distance

Mar 4, 2014

I am trying to write a program that will display a table with "seconds" and "Distance". Where Seconds goes from 1-12 and the distance is displayed according to each second. However I am having trouble getting the distance variable to display any values. By the way I am also using a second function in this program besides main(), called FallingDistance(). Below is my code for the program so far.

#include <iostream>
using namespace std;
double FallingDistance(int, double);
int main() {
int Seconds;
double Distance=0;
int distance;

[Code].....

View 6 Replies View Related

C++ :: Calculate Midpoint And Distance Between Two Points

Sep 25, 2013

I'm creating a quick program to calculate midpoint and distance between two points. I'm having a little trouble. This is the program:

//This program is a start to solve basic coordinatre plane distances and midpoints
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[]){
cout << "This is a calculator to find distance and the midpoint between two points. " ;

[Code]...

the problem is that the output for both equations is wrong, it doesn't do the math properly and I assume it has to do with the variable types I'm using but am not sure. P.S. I am using the latest version of DEV-C++

View 12 Replies View Related

C++ :: Calculating Distance - Cannot Find Directories

Oct 5, 2013

[URL] ....

I've been getting these errors on two computers through four different compilers. It seems the directories arnt set up. If that's the cause, I have no clue how to resolve that.

Its a very simple prog too; it just calculates a dist, using dist formula.

#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
void calcDistance (int x1, int y1, int x2, int y2);

[Code] ....

View 6 Replies View Related

C++ :: Find Distance Of 3 Dimensional Bodies

Nov 7, 2014

I am trying to find the distance of 3 dimensional bodies. I am able to find the two bodies furthest from each other, but i cannot find the bodies closest to each other.

it displays 0(it's body to itself). is there a way to negate the program from comparing it to itself?

The program works but it always find the closest body as itself. Part of the program.

for(int l=0; l<size; l++){
cout<<s[l].getName()<<endl;
int smallest=0;
for(int q=1;q<size;q++){

[Code] .....

View 1 Replies View Related

C :: Program To Find The Square Root Of A Number

Dec 5, 2013

I am writing a program to find the square root of a number. I am using the Newton-Raphson method..Just to clarify a bit of the code.. fabs(1/(x+1)) < 0.001 is to check for relative error..

EXAMPLE: for user entry of 100 if the iteration process ends in 10.055 the answer will return as 10 which is correct. But it isn't doing that.

It compiles I then proceed to run it..prompts me "Enter a number to find the square root of: I type 100 then hit enter...

"The square root of 100 is -1077834936"

My first time writing a program from complete scratch.

And I know there is a sqrt() function...just wanted to write my own.

Code:

#include <stdio.h>
#include <math.h>
double mysqrt(double a);
int main()
{
double a, result;
printf("Enter a number to find the square root of: ");

[Code]...

View 1 Replies View Related

C :: Prototype Function Square Root Velocity

Mar 30, 2013

I am trying to computed the time it takes for a projectile to hit the ground. The problem is that i need to square the input of velocity before i do the calculation. the question I have is that if it's possible to have multiple arguments inside the brackets after main.

#include <stdio.h>
#include <math.h>
double distance (double a, double v, double g);
int square(int y);
double height(double v, double a, double g);
double time (double v, double a, double g);
double sqrt(double num);

[Code] ....

View 2 Replies View Related

C++ :: How To Change Hierarchy Without Passing Root Element

Aug 6, 2013

I got a mesh which has an edge with a specific transformation (translation + orientation). When this configuration / transformation is changed, its neighbours are to be updated. This structure is kept inside a tree so that when a root "frame" is passed to a method like UpdateHierachy, the mesh will recursively update itself.

If, I don't pass this method the root element, which is in my case, how do I change the rest of the structure? The reason to do this is because I want to say move the door, the windows and furniture will move along with it.

View 8 Replies View Related

C++ :: Function That Calculates Euclidean Distance Between Two Points

Feb 24, 2015

I am trying to write a function that calculates the Euclidean distance between two points described by
𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒 = √(𝑥1 − 𝑥2)2 + (𝑦1 − 𝑦2)2
Input Prompt
Enter x1, y1, and x2, y2:
Output Prompt
The distance is XXXX.XXX

Replace XXXX.XXX with the calculated distance precise to three decimal points.

Will this be a smilier input to the same forum that wasted posted a few years ago on this site?

Here is the link... [URL]..

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved