当前位置: 首页 > 面试经验 >

Zoom 杭州C++客户端二面面经

优质
小牛编辑
116浏览
2023-03-28

Zoom 杭州C++客户端二面面经

面试官是技术总监,我想自我介绍一下都不让我介绍了,说我看简历就行。
问了一些项目问题还有职业规划的问题,问项目的技术点,回答的很差,不知道该说什么。
职业规划我说想看见更丰富的世界,不想一个职业干到底。
全程尬聊,之后他说做道题,写一个多叉树,支持添加节点、查询节点、删除、析构。
14:33写到14:52,差不多还写出来了。
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int cnt = 0; 

struct Node
{
    int name; //编号
    int val;  //
    Node* child{};
    Node* right{};
    Node(){}
    Node(int _name, int _val):name(_name),val(_val){}
};

Node* root;

void addBro(Node* fa, int val)
{
    if(fa->child)
    {
        Node* ch = fa->child;
        while(ch->right) ch = ch->right;
        ch->child = new Node(++cnt, val);
    }
    else
    {
        fa->child = new Node(++cnt, val);
    }
}

void add(int father_name, int val)
{
    Node* now = root;
    queue<Node*> Q;
    Q.push(now);
    bool flag = false;
    while(!Q.empty())
    {
        now = Q.front();
        Q.pop();
        if(now->name == father_name)
        {
            addBro(now,val);
            flag = true;
            break;
        }
        if(now->right) Q.push(now->right);
        if(now->child) Q.push(now->child);
    }
    if(!flag) {
        cout << "Not exist this father"<<endl;
    }
}

int query(int name){
    Node* now = root;
    queue<Node*> Q;
    Q.push(now);
    bool flag = false;
    int ans;
    while(!Q.empty())
    {
        now = Q.front();
        Q.pop();
        if(now->name == name)
        {
            ans = now->val;
            flag = true;
            break;
        }
        if(now->right) Q.push(now->right);
        if(now->child) Q.push(now->child);
    }
    if(!flag) {
        cout << "Not exist this father"<<endl;
        return -1;
    }
    else {
        return ans;
    }
}

void depth_del(Node* to_del)
{
    Node* now = to_del;
    queue<Node*> Q; // queue
    vector<Node*> vec;
    Q.push(now->child);

    while(!Q.empty())
    {
        now = Q.front();
        Q.pop();
        vec.push_back(now);
        if(now->right) Q.push(now->right);
        if(now->child) Q.push(now->child);
    }
    for(int i = 0;i<vec.size();i++){
        delete vec[i];
    }
    return;
}

Node* del(int name)
{
    Node* now = root;
    queue<Node*> Q;
    Q.push(now);
    bool flag = false;
    Node* ptr;
    while(!Q.empty())
    {
        now = Q.front();
        Q.pop();
        if(now->name == name)
        {
            ptr = now;
            flag = true;
            break;
        }
        if(now->right) Q.push(now->right);
        if(now->child) Q.push(now->child);
    }
    if(!flag) {
        cout << "Not exist this father"<<endl;
        return nullptr;
    }
    else {
        return ptr;
    }
}

int main(){

}
然后给面试官仔细讲了两遍如何用队列遍历一棵树,已经递归的方式和非递归方式实现树的优缺点。
刚打开牛客准备写面经,就接到hr面的电话,面试刚结束13分钟。。。
#ZOOM##zoom校招##Zoom#
 类似资料: