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#
全部评论
是到hr面了吗
点赞
送花
回复
分享
发布于 2022-09-08 14:01 黑龙江
HR还挂人吗
点赞
送花
回复
分享
发布于 2022-09-09 16:31 北京
秋招专场
校招火热招聘中
官网直投
hi~同学,秋招遇“寒气”,牛客送温暖啦!23届秋招笔面经有奖征集中,参与就得牛客会员7天免费体验,最高赢300元京东卡!戳我去看>>>https://www.nowcoder.com/link/zhengjipinglun
点赞
送花
回复
分享
发布于 2022-09-08 14:05 北京
hxd啥时候hr面呢,求讲讲面试内容
点赞
送花
回复
分享
发布于 2022-09-11 15:11 江苏
兄弟 这个多叉树是面试或简历中提到了才写的 还是直接让写多叉树
点赞
送花
回复
分享
发布于 2022-10-30 22:53 浙江

相关推荐

5 20 评论
分享
牛客网
牛客企业服务