473,396 Members | 1,784 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,396 software developers and data experts.

C B-Tree problem need it important

2
I have a problem
I want to print a B tree by this way
the In put will be: 8 5 3 7 4 2

the out put will be:

8
/ \
3 5
/ \ \
2 4 7

I create the tree bu I can print it I just print it by
level wise
8 3 5 2 4 7
how I can print it ?
step by step.
Mar 23 '07 #1
1 1098
DeMan
1,806 1GB
first work out how wide your screen is (usually about 80 characters)
at each level n, the elements will be 80/(2^n) characters apart (although you may need to take into account the space the characters themselves take up.

If you want a simple check that the binary tree has been created properly (and it appears it probably has) you can simply to a preorder traversal....

Expand|Select|Wrap|Line Numbers
  1.  
  2. printTree(Node n)
  3. {
  4.   printTree(n.Left);
  5.   printf("%d ", n.value);
  6.   printTree(n.Right);
  7. }
  8.  
and the values should all be in order. (This won't tell you for certain that the tree is correct, but ordering things is the most common use for a binary tree, and if you can show that it works for many different cases then it's probably right). If you want to make sure you have a Balanced Binary Tree, you can either print visually as you intended, or have each node print it's value and Depth. Then you make sure you have enough of any particular depth.
Mar 23 '07 #2

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

Similar topics

0
by: Jane Austine | last post by:
Hello. How do I change the BTree sorting order with bsddb, instead of the default lexicographical order? After studying sleepycat's document, I found there is a function call for setting the...
5
by: Nobody | last post by:
I am trying to write a BTree class, just wondering if I missed any useful methods. This is my class definition so far (excuse the MFC portions, its a project requirement): template <class TYPE,...
4
by: Eloff | last post by:
I've got 100MB of urls organized by domain and then by document. I thought that a hastable of hastables or a btree of btrees would be a good way to lookup a specific url quickly by first finding...
4
by: Spam Me Please | last post by:
I have a tree like this struct BTree{ int left; char c; int right; }; #define END -1 int main(int argc, char *argv)
2
by: Mark Harrison | last post by:
I create a table like so: create table types ( typeid integer unique not null, typename varchar(255) unique not null ); and I get the expected messages: NOTICE: CREATE TABLE / UNIQUE...
4
by: os2 | last post by:
hi i would like to catalog my hd and put the data in a btree somebody know how to do it? a hint to begin? thanks
1
by: Brian Maguire | last post by:
Can too many btree indexes cause page level locking? I read this... http://www.postgresql.org/docs/7.4/static/locking-indexes.html
0
by: Rano | last post by:
Hi could u guys look at this assignment sheet and try to help me to display the Btree in this form by using x and y coordinate plzzzzzzz help 10 3 11 2 4
0
by: shamirza | last post by:
· What is view state and use of it? The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested...
0
by: sudhi nair | last post by:
hi dba's i want an automated script for converting btree index (with less cardinality) to bitmap index bcoz old version is 10g std edition now migration to 10g enterp edition any body know pls...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.