Thread: post order iterative help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    450

    post order iterative help

    I have been struggling with implementing a post order iterative traversal of a binary tree. One of the exercises from preludes post. I wracked my brain trying to do it without implementing this state structure, but am having problems debugging having given in to it's use. Here is the code
    Code:
    void post_order_traverse_iterative(tree_node* root, fptraction action)
    {
      
      struct state_node{
        tree_node * header;
        BOOL state;
        state_node(tree_node * hd, BOOL st):header(hd), state(st){};
      };
    
      state_node* temp_state_node=new state_node{0,FALSE};
      struct state_node *save[50];
      int top = 0;
       
        
      while (root != NULL){
        save[top++]=new state_node(root,FALSE);
        root=root->left;
      }
        
      temp_state_node=save[--top];// first error here type mismatch?
          
      if (!(temp_state_node->state)){
          temp_state_node->state=TRUE;
          save[top++]=temp_state_node;
      }
      else{
        temp_state_node=save[--top];
        action(temp_state_node.header);
        delete temp_state_node;
      }  
    }
    I am getting a number of errors, some help getting past the first one would be great. I don't know if the logic is sound but need to fix the syntax error to test it.

    Here are the errors
    binarytree.cc:79: error: invalid conversion from `state_node*' to `int'
    binarytree.cc:81: error: syntax error before `if'
    binarytree.cc:83: error: ISO C++ forbids declaration of `save' with no type
    binarytree.cc:83: error: variable-size type declared outside of any function
    binarytree.cc:83: error: conflicting types for `int save[2]'
    binarytree.cc:70: error: previous declaration as `state_node*save[50]'
    binarytree.cc:84: error: syntax error before `}' token
    binarytree.cc:87: error: request for member `header' in `temp_state_node',
    which is of non-class type `int'
    binarytree.cc:87: error: ISO C++ forbids declaration of `action' with no type
    binarytree.cc:88: error: syntax error before `delete'
    Last edited by curlious; 01-02-2004 at 09:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with HTTP POST
    By Anddos in forum Networking/Device Communication
    Replies: 5
    Last Post: 03-22-2009, 08:41 AM
  2. Post your Best Text Adventure
    By Joe100 in forum Game Programming
    Replies: 3
    Last Post: 08-15-2003, 05:47 PM
  3. Auto POST
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-07-2003, 10:42 AM