首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求大神调试 代码 多谢着急中(代码目的是将string型按char型插入到链表中实现 树型存储。但是没有输出结果求点拨

2013-01-08 
求大神调试 代码 谢谢着急中(代码目的是将string型按char型插入到链表中实现 树型存储。但是没有输出结果求

求大神调试 代码 谢谢着急中(代码目的是将string型按char型插入到链表中实现 树型存储。但是没有输出结果求点拨。
#include <iostream>
#include<string>
#include<cstdlib>
#include<cstring>
using namespace std;
const int size=100;
typedef struct node{
   char a;
   struct node*next;}list,*qlist;
class tree{
     qlist head;
     qlist flag;
   public:
     tree();
     void inserter_tree(string&name);
     void show_tree();
     };
tree::tree(){qlist temp=new list;
              temp->a='#';
              head->next=temp;
              temp->next=NULL;
              flag=temp;
}
void tree::inserter_tree(string&name)
 {
     qlist flag1=flag;int j=name.size();
     for(int i=0;i<j;i++)
     {
          qlist temp=new list;
          temp->a=name[i];
          temp->next=flag1->next;
          flag1->next=temp;
          flag1=flag1->next;
     }
     flag=flag->next;
 }
     void tree::show_tree()
     {
         qlist temp=head;
         while(temp)
       {
           cout<<"show the tree:"<<cout<<temp->a<<'\t';
           temp=temp->next;
           }
           cout<<endl;
     }

int main()
{
    tree ll;
    ll.show_tree();
    string hah="xiaojiba";
    ll.inserter_tree(hah);
    ll.show_tree();
    return 0;
}

[解决办法]
构造函数应该是这样的。
tree::tree()
{
qlist temp=new list;
temp->a='#';
head=temp;
temp->next=NULL;
flag=temp;
}

热点排行