如题

解决方案 »

  1.   

    在文件中,用一个fseek的东东,即文件内的偏移量
    把它想象成内存中的指针,那么,你的问题就解决了
      

  2.   

    前序遍历写入文本文件
    ofstream outfile("outfile.txt");
    treenode 是一个二叉树节点,lchild指向左子树,rchild指向右子树. value为一个值
    struct treenode
    {
       treenode* lchild;
       treenode* rchild;
       int value;
    }
    template<typename valType> preorder(treenode* ptr,ofstream& outfile)
    {
         if(ptr)
         {
          outfile<<ptr->value;
          if(ptr->lchild) preorder(ptr->lchild,outfile);
          if(ptr->rchile) preorder(prt->rchile,outfile);
          }
    }读文件就是一个反向生成二叉树过程
      

  3.   

    模板template<typename valType>没用,函数少了个返回参数 void
      

  4.   

    也就是二叉树的线索化就行了
    二叉树按中序线索化的算法
      typedef enum { Link,Thread} PointerTag; //枚举值Link和Thread分别为0,1
      typedef struct node{
          DataType data;
          PointerTag ltag,rtag; //左右标志
          Struct node *lchild,*rchild;
        } BinThrNode;\\线索二叉树的结点类型
      typedef BinThrNode *BinThrTree;
      BinThrNode *pre=NULL; //全局量  void lnorderThreading(BinThrTree p)
        {//将二叉树p中序线索化
          if(p){ //p非空时,当前访问结点是*p
                 InorderThreading(p->lchild); //左子树线索化
                     //以下直至右子树线索化之前相当于遍历算法中访问结点的操作
                 p->ltag=(p->lchild)?Link:Thread; //左指针非空时左标志为Link
                                                 //(即0),否则为Thread(即1)
                 p->rtag=(p->rchild)?Link:Thread;
                 *(pre){ //若*p的前趋*pre存在
                       if(pre->rtag==Thread) //若*p的前趋右标志为线索
                            pre->rchild=p; //令*pre的右线索指向中序后继
                      if(p->ltag==Thread) //*p的左标志为线索
                           p->lchild=pre; //令*p的左线索指向中序前趋
                     } // 完成处理*pre的线索
                 pre=p; //令pre是下一访问结点的中序前趋
                 InorderThreeding(p->rehild); //右子树线索化
               }//endif
        } //InorderThreading