Solved

Stacks and Queue ( this is not a homework problem)

Posted on 2004-04-14
5
354 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

821 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