Thread: Printing Tree in FIFO manner?

  1. #1
    Bufflo
    Guest

    Question Printing Tree in FIFO manner?

    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.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >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.

  3. #3
    Bufflo
    Guest

    Question

    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~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. Binary Tree, couple questions
    By scoobasean in forum C Programming
    Replies: 3
    Last Post: 03-12-2005, 09:09 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM