473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

function returning the width of tree

momotaro
357 100+
am trying to write a function that will return the width of a linked binary tree, that is, the maximum number of nodes on the same level and this is what I ve come up with:

Expand|Select|Wrap|Line Numbers
  1. int TreeWidth(Tree *root){
  2. Queue *q = NewQueue();
  3. Tree *temp;
  4. Append(q, root);
  5. while(!QueueEmpty(q)){
  6. Serve(q, &temp);
  7. if(temp->left != NULL) Append(q, temp->left);
  8. if(temp->right != NULL) Append(q, temp->right);
  9. int Size = (int) TempSize = QueueSize(q);
  10. if (Size < TempSize) size = TempSize;
  11. else Size = Size;
  12.        }
  13. return Size;
  14. }
if there is any better implimentation please help!
THX!
Apr 26 '07 #1
1 1967
momotaro
357 100+
is this algorithm correct? THK!
Apr 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: j | last post by:
Hi, Anyone out there with binary search tree experience. Working on a project due tomorrow and really stuck. We need a function that splits a binary tree into a bigger one and smaller one(for a...
5
by: J Lake | last post by:
I am working on a simple orderform script to keep a running total, however I am encountering some errors. function CalculateTotal() { var order_total = 0 // Run through all the form fields...
8
by: Matt Kruse | last post by:
I've found that under some circumstances, some code that I've been using to find an object's coordinates with respect to the viewport does not behave correctly. Is there a function that has been...
4
by: hzgt9b | last post by:
Using VS.NET 2003, VB: I have a TreeView object with lots of nodes. The treeview is docked on the left side of my main from in a splitter. I want to set the splitter's initial width to allow all...
3
by: noahlt | last post by:
I'm trying to write a website updating script, but when I run the script, my function to search the DOM tree returns None instead of what it should. I have this program: -------- import sys...
5
by: Taras_96 | last post by:
Hi everyone, Can anyone tell me why the top paragraph block stretches across the screen (as you would expect), while the bottom div doesn't stretch across the entire screen? When I set the width...
3
by: empiresolutions | last post by:
I'm trying to build my first PHP Class. After days of tweaking, im lost. I am used to working with functions and arrays, but wrapping them in classes is confusing me. The following code is to...
1
by: soospecial81 | last post by:
This lab will allow you to practice using value returning functions Please read all directions before beginning. You will turn in two programs (L5_P1.cpp and L5_P2.cpp). Be sure to include you and...
2
by: ndeeley | last post by:
Hello, I've written a script which returns the admin rights of users in a table - their access level, and their priviledges. The priviledge are returned to a check box and the admin rights to a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.