c++笔试题目

来源:互联网 发布:php在线文档系统 编辑:程序博客网 时间:2024/05/30 23:08

N人报数问题

 

 

判断单链表是否有回路

 

 

逆向输出:

1、逆向链表:

 

链表修改成逆向:

 

推理可得逆向输出字符串:

 

 

 

链表逆向递归实现:

 

 

 

C++编成求二叉树的深度;

 

 

 

C++编成求二叉树的深度;

intbinTreeDepth(link *head){
   int depthl=0,depthr=0;
   if(head==null)
              return 0;
   else{
             if ((head->left)!=null)
                    depthl = 1 + binTreeDepth(head->left);
             if ((head->right)!=null)  
                    depthr = 1 + binTreeDepth(head->right);
             return depthl>depthr?depthl:depthr;
   }
}

 

原创粉丝点击