新手一枚,学习中,,,,,总结一下昨天第一次面试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;
}
回答问题需严谨,有条有理,要全面,要用专业的术语!!!
对于编程题,一定要理解问题,有步骤的进行,先从简单的方向入手,然后考虑代码的性能及优化!!!
后续会不断的学习 整理答案,,,,,