腾讯3.28客户端面试一面面经

开始自我介绍,问项目,然后问基础知识,操作系统,网络,C++这些,最后两道编程题。

 

冒泡排序的递归写法:

自己开始写的双层for循环的写法,自己开始写的神奇方法把自己和面试官都搞懵逼了,后来发现自己写的代码其实是有问题的,并不是冒泡排序(相邻两个数,比较交换),只是每次保证i位置元素最小,类似选择排序?

#include <iostream>
using namespace std;

void bubble_sort(int arr[], int n){
    for(int i = 0; i < n; i++){
      for(int j = i; j < n; j++){
        if(arr[i] > arr[j]){
            swap(arr[i], arr[j]);
        } 
    }
    }
}
int main() {
    int arr[] = {5, 4, 2, 3, 6};
    int n = 5;
    bubble_sort(arr, 5);
    for(int i = 0; i < n; i++){
        cout<<arr[i]<<endl;
    }
}

然后在面试官的提示下改成了递归写法,去掉了一个for,一层一层递归,还是类似选择排序的方法。 

#include <iostream>
using namespace std;

void bubble_sort(int arr[], int i, int n){
   for(int j = i; j < n; j++){
        if(arr[i] > arr[j]){
            swap(arr[i], arr[j]);
        } 
   }
   if( i < n ) bubble_sort(arr, i + 1, n);
}
int main() {
    int arr[] = {5, 4, 2, 3, 6};
    int n = 5;
    bubble_sort(arr, 0, 5);
    for(int i = 0; i < n; i++){
        cout<<arr[i]<<endl;
    }
}

最后自己查了一下,这个才是真正的冒泡排序啊!比较相邻元素,大元素上冒,然后每次上边界-1

加一个flag判断,假如不需要排序了,直接退出即可

非递归写法

#include <iostream>
using namespace std;

void bubble_sort(int arr[], int n) {
    for (int i = n - 1; i >= 0; i--) {//排序的上界,每次减1
        int flag = 0;
        for (int j = 0; j < i; j++) {
            if (arr[j] > arr[j + 1]) {
                swap(arr[j + 1], arr[j]);
                flag = 1;
            }
            if (!flag) return;
        }
    }
}
int main() {
    int arr[] = { 5, 4, 2, 3, 6 };
    int n = 5;
    bubble_sort(arr, 5);
    for (int i = 0; i < n; i++) {
        cout << arr[i] << endl;
    }
}

 递归写法, 上界要写成n-1,防止越界

#include <iostream>
using namespace std;

void bubble_sort(int arr[], int n) {
    int flag = 0;
    for (int i = 0; i < n - 1; i++) {
        if (arr[i] > arr[i + 1]) {
            swap(arr[i + 1], arr[i]);
            flag = 1;
        }
    }
    if (!flag) return;
    if (n > 0) bubble_sort(arr, n - 1);
}
int main() {
    int arr[] = { 5, 4, 2, 3, 6 };
    int n = 5;
    bubble_sort(arr, 5);
    for (int i = 0; i < n; i++) {
        cout << arr[i] << endl;
    }
}

实现双向队列,实现头尾插入或者删除

写队列,自己直接就想到了数组的方法,写完之后面试官就问如果超出容量怎么办;想了一会才想到采用链表的方法,真是太菜了。

然后在写的过程中发现对于类的定义和指针操作这些不熟练,边写边害怕是不是写错了。

#include <iostream>
using namespace std;


class deque {
    struct Node {
        int num;
        Node* pre;
        Node* next;
        Node(int n) :num(n), pre(NULL), next(NULL) {
        }
    };
    struct Node* front;
    struct Node* back;

public:
    deque(int num) {
        front = new struct Node(num);
        back = front;
    }
    void front_insert(int num) {
        struct Node* ptr = new struct Node(num);
        front->next = ptr;
        ptr->pre = front;
        front = front->next;
    }
    void back_insert(int num) {
        struct Node* ptr = new struct Node(num);
        back->pre = ptr;
        ptr->next = back;
        back = back->pre;
    }
    void front_delete() {
        struct Node* tmp = front;
        front = front->pre;
        front->next = nullptr;
        delete tmp;
    }
    void back_delete() {
        struct Node* tmp = back;
        back = back->next;
        back->pre = nullptr;
        delete tmp;
    }
};
int main() {

    deque q(-1);
    q.front_insert(2);
    q.back_insert(2);
    q.front_insert(4);
    q.back_insert(5);
    q.front_delete();
    q.back_delete();
    return 0;
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 腾讯android社招面试题除了要求基本的编程基础外,更加注重应聘者的思路和解决问题的能力。例如,有一道题目是让应聘者解决一个弹球游戏的碰撞问题,考察了应聘者对物理学原理的了解程度和建模思维的能力。而另外一道题则是要求应聘者自己设计一个数据结构,并写出相关的代码,考察了应聘者对数据结构的掌握程度以及解决实际问题的能力。 此外,腾讯面试也注重应聘者的团队合作能力,例如会询问应聘者过往参与的项目经历以及其中的角色和职责。面试官还会关注应聘者平时的兴趣爱好和学习方式,看重自我发展和持续学习的态度。 总的来说,腾讯android社招面试注重应聘者的思考方式和解决问题的能力,希望应聘者能够在面试中展现出技术实力的同时也能够体现出比较全面的素质和团队合作技巧。 ### 回答2: 首先,我认为腾讯是一家非常优秀的公司,成熟的技术、稳定的业务、开放的文化及良好的薪酬待遇,这些都是我希望所在公司所具备的。当然,现如今,安卓技术在移动互联网领域已经越来越普及,所以我对腾讯Android社招面试也充满期待。 鉴于腾讯一贯的严谨和高要求,我认为其社招面试中会涉及到个人技能、团队协作能力、沟通能力及学习能力等,且可能会采用多种形式的测试与考核方式,如笔试、技术面试、项目经历考核等。而我会尽最大努力,从细节和思路等方面准备自己,积极展示自己的能力和素养,在适当的时候提问与反问,来表现出自己的个性魅力和职业素养。总之,我会以最好的状态去应对腾讯Android社招面试,尽我所能去展现自己,来赢得这个职位的机会。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值