As we know, tree structure have many advantage over linked list. And it is usual to print tree in an "alphabetical" order. However, is it possible to print the elements of a tree in an FIFO order?
Thanks if you can help.
As we know, tree structure have many advantage over linked list. And it is usual to print tree in an "alphabetical" order. However, is it possible to print the elements of a tree in an FIFO order?
Thanks if you can help.
>However, is it possible to print the elements of a tree in an FIFO order?
Well...you can, but I say that with hesitation because the design of trees makes an operation like this imprecise and impractical, or difficult. I suppose you could treat the tree like a parse tree and have each successive entry placed in a node further to the right of the tree. Then when you balance the tree you can do an reverse-order traversal and print the values as they were entered.
It really is better to use a linked list in this case IMHO.
-Prelude
My best code is written with the delete key.
Originally posted by Prelude
>However, is it possible to print the elements of a tree in an FIFO order?
Well...you can, but I say that with hesitation because the design of trees makes an operation like this imprecise and impractical, or difficult. I suppose you could treat the tree like a parse tree and have each successive entry placed in a node further to the right of the tree. Then when you balance the tree you can do an reverse-order traversal and print the values as they were entered.
It really is better to use a linked list in this case IMHO.
-Prelude
You are right. We better use linked list for FIFO output to screen. However, Linked List have a great disadvantage. It is less efficient in searching elements. That's why I want a tree.
How can I combine the two advantages?
1. Print elements to screen in FIFO manner.
2. High element search efficiency.
Will there be any source code making it possible?
Or we simply need another new type of data structure which I have never heard before?
Please Help. Thanks~