Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Stacks and Queue ( this is not a homework problem)

Posted on 2004-04-14
5
Medium Priority
?
360 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 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

926 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