回复: 0
跳转到指定楼层
上一主题 下一主题
收起左侧

自动驾驶公司 Zoox 两轮电面挂经

🔗
匿名用户-IPQHR  2020-2-24 03:47:35 |倒序浏览

2019(10-12月) 码农类General 硕士 全职@zoox - 网上海投 - 技术电面  | | Fail | 在职跳槽

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
面的 embedded software engineer,面了两轮是因为第一轮那个组面完不知道什么原因觉得不合适,把我扔给了另一个组。

第一轮电面,给一个 Exampl
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
关于起点和终点的更新稍微糊涂了几分种,唉。
不多说,这是楼主事后写的一个可以跑的。

  1. #include <stdio.h>
  2. #include <stdlib.h>

  3. class NewQueue {
  4. public:
  5.     NewQueue();
  6.     ~NewQueue();
  7.     void creatNew(int size);
  8.     bool enQueue(int& element);  // return true if data is not been overwritten
  9.     bool deQueue(int& element);  // return is data is been successfully poped
  10.     bool isFull();
  11.     bool isEmpty();
  12. private:
  13.     int capacity;
  14.     int head;  // head points to the next element to be poped
  15.     int tail;  // tail points to the next position for insertion
  16.     bool coincide;  // indicate queue empty if head == tail
  17.     int* data;
  18. };

  19. // both head and tail moves forward
  20. // no need to track the size of the buffer, no member function uses it directly

  21. NewQueue::NewQueue() {
  22.     head = 0;
  23.     tail = 0;
  24.     coincide = true;
  25.     data = NULL;
  26. }

  27. NewQueue::~NewQueue() {
  28.     if (data != NULL)
  29.         free(data);
  30. }

  31. void NewQueue::creatNew(int size) {
  32.     data = (int*) malloc(size*sizeof(int));
  33.     capacity = size;
  34. }

  35. bool NewQueue::isFull() {
  36.     return (head == tail && !coincide);
  37. }

  38. bool NewQueue::isEmpty() {
  39.     return (head == tail && coincide);
  40. }

  41. bool NewQueue::enQueue(int& element) {
  42.     bool result = isFull();
  43.     if (isEmpty())
  44.         coincide = false;
  45.     data[tail] = element;
  46.     tail = (tail + 1) % capacity;
  47.     printf("enQueue success: %d", element);
  48.     if (result) {
  49.         head = (head + 1) % capacity;
  50.         printf(" (overwritting element)");
  51.     }
  52.     printf("\n");
  53.     return result;
  54. }

  55. bool NewQueue::deQueue(int& element) {
  56.     if (isEmpty()) {
  57.         printf("deQueue failed\n");
  58.         return false;
  59.     }
  60.     element = data[head];
  61.     head = (head + 1) % capacity;
  62.     if (head == tail)
  63.         coincide = true;
  64.     printf("deQueue success: %d\n", element);
  65.     return true;
  66. }

  67. int main() {
  68.     NewQueue q;
  69.     q.creatNew(5);
  70.     int var;
  71.     for (int i=0; i<10; i++) {
  72.         q.enQueue(i);
  73.     }
  74.     for (int i=0; i<10; i++) {
  75.         q.deQueue(var);
  76.     }
  77.     return 0;
  78. }
复制代码


评分

参与人数 2大米 +10 收起 理由
匿名用户-Y1D22 + 9
comeonzoe + 1 赞一个

查看全部评分


上一篇:自动驾驶公司 Cruise 电面+onsite 挂经
下一篇:Twitter OA
您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表