C/C++实习面试(一)

新手一枚,学习中,,,,,总结一下昨天第一次面试C/C++实习岗位中的相关问题(STL,数据结构和算法偏多)

1、C++11

2、数组和链表的区别

3、STL中有哪些容器,它们之间的区别

4、vector和list的区别

5、map和hash_map的区别

6、红黑树有什么特性

7、二叉搜索树相较于哈希表的优势

8、数组、链表、二叉树、哈希表的性能比较

9、vector和list中有哪些算法

10、编程题:如果某个整数x(x>=1)存在一个数组中,则2*x+1和3*x+1也必定在这个数组中,已知1为该数组中的元素,现给定一个整数k(k>=1),要求求出该数组中的第k大的数。例如a[3]={1,2,3},当k=1,则返回3;k=2,则返回2;k=3,则返回1;k>=4或k<1,输出错误。

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


void Findkth(int k)
{
vector<int>v;
v.push_back(1);
for(int i=1,count1=1;count1<=k/2;i=2*i+1)
{
v.push_back(2*i+1);
v.push_back(3*i+1);
count1=count1+2;
}
for(int j=4,count2=1;count2<=k/2;j=3*j+1)
{
v.push_back(2*j+1);
v.push_back(3*j+1);
count2=count2+2;
}
vector<int>::iterator iter;
cout<<"before sorting: ";
for(iter=v.begin();iter!=v.end();++iter)
{
cout<<*iter<<" ";
}
cout<<endl;

sort(v.begin(),v.end());

cout<<"after sorting: ";
for(iter=v.begin();iter!=v.end();++iter)
{
cout<<*iter<<" ";
}
cout<<endl;

cout<<"output kth number: "<<v[k-1]<<endl;
}


int main()
{
int k;
cout<<"enter the value of k: ";
cin>>k;
Findkth(k);

return 0;
}



回答问题需严谨,有条有理,要全面,要用专业的术语!!!

对于编程题,一定要理解问题,有步骤的进行,先从简单的方向入手,然后考虑代码的性能及优化!!!

后续会不断的学习 整理答案,,,,,


  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值