Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Stacks and Queue ( this is not a homework problem)

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

Technology Partners: 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

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
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.

730 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