【面试】58同城-Linux后台开发实习生
2015-08-24 12:12
721 查看
昨天下午去面试了58同城的Linux后台开发实习生,发挥的很不好,很多基础问题都答不上来。马上要校招了,还是要加强基础学习啊!血的教训,基础非常重要!!!
1.写出二叉树的深度优先遍历和广度优先遍历。
这其实是一道特别基础的算法题,博主当时是用队列实现的广度遍历,用递归实现的深度遍历。后来面试官又问我,不用递归怎么来实现深度遍历,当时二了,没有想过来,其实和广度遍历类似,用栈来实现就好了。代码:
2.STL中map实现的原理,以及map中[]符号的查找操作。
这个问题回答的并不好,回来也恶补了一下map的知识。STL中map和vector还是要重点掌握啊,这里推荐两篇博文:1)STL中map用法详解,http://blog.csdn.net/it_yuan/article/details/22697205;2)小心使用STL中map的[]操作符,http://blog.csdn.net/starlee/article/details/2256054。
3.C++中const的用法。
推荐文章:http://www.cnblogs.com/xudong-bupt/p/3509567.html
4.写一个多态的demo。
当时博主就傻了,不知道怎么写了。。。当时主要是懵了,其实可以写一个简单的函数多态,比如下面这个小例子:
感悟:自己的基础知识还是太差,一定要恶补自己的基础知识。
1.写出二叉树的深度优先遍历和广度优先遍历。
这其实是一道特别基础的算法题,博主当时是用队列实现的广度遍历,用递归实现的深度遍历。后来面试官又问我,不用递归怎么来实现深度遍历,当时二了,没有想过来,其实和广度遍历类似,用栈来实现就好了。代码:
struct Tree { Tree *left; Tree *right; int val; Tree(int x):val(x),left(NULL),right(NULL) {} }; void width(Tree *root) { if (root == NULL) { return; } queue<Tree *> nodes; Tree *temp; nodes.push(root); while(!nodes.empty()) { temp = nodes.front(); nodes.pop(); cout<<temp->val<<"\t"; if (temp->left) { nodes.push(temp->left); } if (temp->right) { nodes.push(temp->right); } } } void depth(Tree *root) { if (root == NULL) { return; } cout<<root->val<<"\t"; depth(root->left); depth(root->right); } void depthByStack(Tree *root) { if (root == NULL) { return; } stack<Tree *> nodes; Tree *temp; nodes.push(root); while(!nodes.empty()) { temp = nodes.top(); nodes.pop(); cout<<temp->val<<"\t"; if (temp->right) { nodes.push(temp->right); } if (temp->left) { nodes.push(temp->left); } } }
2.STL中map实现的原理,以及map中[]符号的查找操作。
这个问题回答的并不好,回来也恶补了一下map的知识。STL中map和vector还是要重点掌握啊,这里推荐两篇博文:1)STL中map用法详解,http://blog.csdn.net/it_yuan/article/details/22697205;2)小心使用STL中map的[]操作符,http://blog.csdn.net/starlee/article/details/2256054。
3.C++中const的用法。
推荐文章:http://www.cnblogs.com/xudong-bupt/p/3509567.html
4.写一个多态的demo。
当时博主就傻了,不知道怎么写了。。。当时主要是懵了,其实可以写一个简单的函数多态,比如下面这个小例子:
int add (int num1,int num2) { return num1+num2; } int add (int num1,string str1) { return num1+atoi(str1.c_str()); } int _tmain(int argc, _TCHAR* argv[]) { int a1 = 1; int a2 = 2; string str ="2"; cout<<"函数多态add(int num1,int num2)的结果是:"<<add(a1,a2)<<endl; cout<<"函数多态add(int num1,string str1)的结果是:"<<add(a1,str)<<endl; return 0; }
感悟:自己的基础知识还是太差,一定要恶补自己的基础知识。
相关文章推荐
- wget命令
- linux udp通讯发包最少代码
- 【马哥linux学员学习笔记】zabbix实现微信报警
- Tickr:一个开源的 Linux 桌面 RSS 新闻速递应用
- linux动态库路径配置
- Linux文件传输scp和rsync断点续传
- Linux下安装过程中编译PHP时报错:configure: error: libjpeg.(a|so) not found
- CentOS6.5 单独编译安装PHP gd库扩展
- Linux下查看文件内容的命令
- centos之开放80端口
- Linux硬连接、软连接的原理 兼述磁盘组成&文件系统类型
- Linux 内核学习之内存寻址(二) Linux内存寻址
- centos7中systemctl查看服务
- Linux 下安装python软件包(pip、nose、virtualenv、distribute )
- Linux下的软件安装
- Ubuntu下Linux安装Jdk及环境变量配置
- Linux可靠信号和不可靠信号
- LINUX 笔记8
- LINUX笔记7
- LINUX笔记6