C++ :: AVL-tree Calculate Height Difference?

Sep 28, 2014

I looking for method which can give me the height difference of an AVL_tree.

The method i come up with up now is this.

int avl_tree::balance(node* pointer)
{
while (pointer->left != NULL) {
int left = balance(pointer ->left);
}
while (pointer->right != NULL) {
int right = balance(pointer->right);
}
return left - right;
}

Which recursively calls itself, but the problem is that i get stuck on the first line..

View 4 Replies


ADVERTISEMENT

C++ :: Height Or Depth Of Binary Tree

Feb 23, 2014

I'm in interested to know what will be the height of binary tree with say 5 nodes (consider it balanced) is it 2 or 3?

9
/
5 13
/
3 7

and for following tree also:

2
/
7 5
/
2 6 9
/ /
5 11 4

is it 3 or 4?

i'm asking because, not able to find correct/one answer.

the algorithm i find is:

depth(struct tree*t) {
if ( t == NULL) return 0;
return max( depth(tree->left), depth(tree->right) ) + 1;
}

According to it, ans for second will be 4

But as per image on wikipedia [URL] .... the ans is 3

View 6 Replies View Related

C++ :: Binary Tree - Find Height With Recursive Function

Feb 21, 2015

For an assignment I have to finish prewritten code which consists of multiple source files and a header file.

Code:
#include "tree.h"
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

[Code] .....

I understand that I have to find the height by using _left->height() and _right->height() as long as it is not a null-pointer , each time I do this the values of _left and _right change. That way you can check if it is possible to go further down in the tree. I also have to use a counter to keep track of the number of layers at each side of the root. I don't understand how to implement it.

View 3 Replies View Related

C/C++ :: Calculate Volume Of A Cone With Values For Diameter Of Base And Height

Jan 30, 2014

I am having trouble with calculating the volume of a cone

Assignment: Using the knowledge you already have, create, build, run, and correct if necessary a program that will calculate the volume of a cone. Insert into your code values for diameter of the base and the height. Use variables, constants, literals, and mathematics as necessary.

The formula for the volume is:

1/3 π x Radius2 x Height

Hint: you will need to add to your program two lines where appropriate:

#include <cmath>
const double PI = 2*acos(0.0);

Here is my current code:

#include <iostream>
using namespace std;
int main () {
//diameter of the base
float diameter = 3;

[Code] ....

View 3 Replies View Related

C++ :: Difference Between Binary Search Tree And Linked List

Oct 30, 2014

What is the difference between BST and linked list? Or are BST implemented through linked list?

View 6 Replies View Related

C :: Program To Calculate Difference In Time?

Nov 6, 2014

i writing a code which will calculate the difference between time_in and time out. Can i use a 2 dimensional array for example

int time_in[hours][minutes]
int time_out[hours[minutes]

View 3 Replies View Related

C :: Program Which Calculate Time Difference Between Two Daytime

Jul 4, 2013

I'm challenged to write a program which calculates the time difference between two daytime.

compiler doesn't give an error, yet the warning: "format '%d' expects argument of type 'int *', but argument 3 has type 'int' [- Wformat]" for lines 24 and 26

However, by entering the first time the program crashes anyway. so I assume I do really need some pointer to make it read from the console can you see where my problem is?

Code:

#include <stdio.h>
#include <stdlib.h>
typedef struct {
int Second;
int Minute;
int Hour;
}Time;

[Code]...

View 4 Replies View Related

C/C++ :: Find Maximum Element From A Tree (not A Binary Tree)

Oct 31, 2014

I want to find maximum element from a tree (not a binary tree ) ???? ...using c language...

View 1 Replies View Related

C# :: Width And Height For Column And Rows

Mar 21, 2014

Basically when I type in different widths and heights for the col and rows, the buttons that make up the width get cut off. Something is messed up but I'm not sure what!

InitializeComponent();
int _col = int.Parse(cols);
int _row = int.Parse(rows);
int width = groupBox1.Width;
int height = groupBox1.Height;
int bW = width / _col;
int bH = height / _row;

[Code] ....

View 4 Replies View Related

C# :: How To Size ListBox Height To Items

Jul 24, 2014

Is there a way to set the height of a listBox to show all of the items without having to kick in the vert scrollbars? I've searched on this question but can't find how to do this.

I want to kind of auto-size my listBox height to accommodate my items (within reason and perhaps set a max height which would kick in the vert scroll bars.

View 9 Replies View Related

C/C++ :: How To Use Rectangle Height And Width In Functions

May 13, 2014

The problem says:

Define functions n(), s(), e(), w(), center(), ne(), se(), sw() and nw(). Each takes a Rectangle argument and returns a Point. These functions define connection points on and in the rectangle. For example, nw® is the northwest (top-left corner) of a rectangle called r.

I wrote below code for that:

#include <Simple_window.h>
Point n(const Graph_lib::Rectangle& r);
Point s(const Graph_lib::Rectangle& r);
Point e(const Graph_lib::Rectangle& r);
Point w(const Graph_lib::Rectangle& r);
Point ne(const Graph_lib::Rectangle& r);
Point se(const Graph_lib::Rectangle& r);

[Code]...

As you see, this just mark the top-left corner of the rectangle r. In other functions I need the specifications of that rectangle, for example its height and width. How to use these specs in those functions?

View 2 Replies View Related

Visual C++ :: How To Adjust Combobox Height

Dec 30, 2013

how to adjust the combo box height?

I can adjust the combo box width and also the dropdown list height but not the combo box height.

View 12 Replies View Related

Visual C++ :: Width And Height From HBITMAP?

Sep 5, 2013

If I get a bitmap from the clipboard with:

hBitmap=(HBITMAP)GetClipboardData(CF_BITMAP);

...how do I get the width and height ? Can I get at the BITMAPINFO ?

View 2 Replies View Related

Visual C++ :: Vertical Size / Height Of Control Bar In MDI App?

Jan 28, 2014

In a MDI-app with some toolbars and statusbar I created also a controlbar which can be docked to the left side. My problem now: how do I get the exact height of the controlbar?

In CalcDynamicLayout I set the height for the docked state to the height of the mainframe. This value is too big, but it will work basically.

But how can I get the exact height of the controlbar?

View 4 Replies View Related

C/C++ :: Input User Name And Height In Inches And Output In Centimeters

Oct 22, 2012

I am attempting to write a simple C program, in which the user is asked to input their name and height in inches and the output is the user's height in centimeters.

I have attached my program and what happens when I try to run it.

Attached Images : PM.jpg (120.6 KB)

View 1 Replies View Related

Visual C++ :: Find Correct Font (height) For Text?

Mar 20, 2014

my problem:I have a text (singleline) and a fix width for the whole text.

How do I find the correct font (height) for this text?

View 8 Replies View Related

Visual C++ :: Change Item Height In CListBox / CListCtrl

Jul 1, 2014

I need a ownerdraw CListBox where I can change the item height during working with the list. The msdn says that I can specify the height in OnMeasureItem when the listbox will be created (ownerdrawfixed) or when an item will be inserted (ownerdrawvariable).

How to change the height e.g. when I click a button?

I made also some tests with CListCtrl. There I can change the height. But there is only one height for all items. How to set individual heights for the items?

View 14 Replies View Related

Visual C++ :: How To Change Height And Width Of PNG Image Dynamically

Mar 4, 2013

I m trying to load a png image by giving the dimension of my own.

CImage Image;
Image.Load (L"D:ImagesPNG_ImagesImage7.png");

But here what happens is that I m not able to give my own dimensions.My code requires constant changing of dimensions of the image.

I tried using libpng.lib in my code.But I dono the keywords for loading the png image after including the lib.

I m using Visual Studio 2010. I m developing in vc++.

How do I load and change the height and width of a png image?

View 4 Replies View Related

C++ :: Input Length / Width And Height For 3 Boxes - Sum And Average Volume

Dec 6, 2013

How would I make it so that I can have someone input the length, width and height for all 3 boxes and then have it output the sum and average volume? Here's an example of what I would like:

INPUT - Enter Box 1 (Length, Width, Height): 10.1 11.2 3.3
INPUT – Enter Box 2 (Length, Width, Height): 5.5 6.6 7.7
INPUT – Enter Box 3 (Length, Width, Height): 4.0 5.0 8.0
OUTPUT – The sum of the volume is 812.806
OUTPUT – The average volume is 270.935

Here's my original code:

#include <iostream>
using namespace std;
double box(double length, double width, double height); // use double data
int main() {
double sum;
sum = box(10.1, 11.2, 3.3) + box(5.5, 6.6, 7.7) + box(4.0, 5.0, 8.0);

[Code] .....

View 1 Replies View Related

C++ :: Demonstrate Usage Of Each Member Function Using Test Data (width And Height)

Feb 11, 2013

Provide the definitions for the following class declaration and then write a program that demonstrates usage of each member function using the test data of 10 for width and 8 for height. Remember to put your main program, class header and class source into separate files. This is an easier version of the exercise than the one you have been asked to practice. Only provide code for the methods specified in the class declaration. Note that the displayRectangle() method should output an appropriate ‘box’, its dimensions, area and perimeter to the screen.

class Rectangle {
public:
Rectangle(int height, int width);
~Rectangle(void);

[Code] .....

View 1 Replies View Related

C++ :: Create Binary Search Tree Template To Be Used To Create AVL Tree

Feb 10, 2013

For my data-structures class, I am attempting to create a binary search tree template to be used to create an AVL tree. I've written a Generic_Tree template for the BST to inherit from, and before I jump into implementing the AVL tree I'm testing the BST member functions. Everything was compiling fine until I added the BST insert() function. Now, I'm getting the following error message from my linker:

undefined reference to 'BST<void>::insert(int, void*)'

Stemming from the call in main line 16.

my makefile compiles with:
g++ -Wall -g Generic_Tree.cpp BST.cpp barfing.cpp main.cpp

Generic_Tree:

template < typename NODE_DATA, unsigned MAX_KIDS >
class Tree {
protected:
struct NODE {
NODE_DATA* contents;
Tree* child[MAX_KIDS];
Tree* parent;

[Code] ....

I'm use to c and havn't used classes or templates before (except for declaring instances of them). The whole syntax is mystifying to me,.

View 4 Replies View Related

C++ :: Difference Between F And Fn

Jan 26, 2013

#include <functional>
using namespace std;

template<typename...Args>
void on(function<void(Args...)> f) {
function<void(Args...)> fn; // this line causes error C2059: syntax error : '<fake-expression>'
}
int main() {
function<void()> f;
on(f);
}

What's the difference between 'f' and 'fn'?

View 3 Replies View Related

C++ :: Difference Between Enumeration With And Without Name

Jun 14, 2014

Code: enun{go, stop, ready, halt}
vs
enum status{go, stop, ready, halt}; and where is enumeration with name is benefficial.

View 7 Replies View Related

C++ :: Difference Between Int And Short Int

Aug 19, 2014

size of int is 2 bytes and of short int is also 2 bytes.The range of values for int and short int are the same.

Then why int and short int are used? only int or short int is enough ....

View 4 Replies View Related

C# :: Difference Between Char And Int

Feb 5, 2015

Creating a C# program to prompt the user to choose the correct answer from a list of answer choices of a question and if the answer is wrong then try to prompt the same question again with do while loop but it is not working as it suppose to be.

class Program
{
static void Main(string[] args {
char UserChoice = ' ';
do {
Console.WriteLine("What is the command keyword to exit a loop in C#?");
Console.WriteLine("a.quit");
Console.WriteLine("b.continue");

[Code] ....

But if i use int instead of char in this program and replace a, b, c and d with 1, 2, 3 and 4 then this program work fine. What is wrong in this code when using char

View 5 Replies View Related

C/C++ :: Difference Between Two Dates?

Oct 26, 2013

How i can easly calculate the difference between two dates ?

Example :

Date 1 = 12 March(3)
Date 2 = 24 November(11)

Result = 258 days

how to do this in C++ ?Btw i don't want to use date functions or something like that.I want to do it with simple math formula.

View 2 Replies View Related







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