Solved

Stacks and Queue ( this is not a homework problem)

Posted on 2004-04-14
5
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Test against App 49 139
Read file descriptor 3 in C 14 128
C dll call freezes 5 116
How to pass pointer to int when expected type is pointer to const char *   ? 6 76
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…
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…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

738 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