Solved

Stacks and Queue ( this is not a homework problem)

Posted on 2004-04-14
5
349 Views
Last Modified: 2011-10-03
If i had a  binary tree structure  like this:

         5          .......Level 1
   2 3     1 4    .......Level 2
how can i print out the levels from the bottom up?
can i use queue to print it out?

 what if i used stack structure instead of queue?
what is the order then?
what kind of traversal will this be after i used stack?
0
Comment
Question by:ptwlee888
  • 3
  • 2
5 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 125 total points
ID: 10821399
Hi ptwlee888,
> how can i print out the levels from the bottom up?
> can i use queue to print it out?
A dequeue will be more convenient ...
Traverse using BFS ... Insert all elements at the tail of dequeue ... Print from the tail of the dequeue

>  what if i used stack structure instead of queue?
> what is the order then?
> what kind of traversal will this be after i used stack?
BFS push on stack ... same result

Sunnycoder
0
 

Author Comment

by:ptwlee888
ID: 10821434
hi sunnycoder

what does BFS stand for
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10821460
breadth first search
0
 

Author Comment

by:ptwlee888
ID: 10821472
ah of course , that makes sense now


thanks sunnycoder
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10821477
glad to be of assistance :o)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now