BIGO面经

  从这次面试中我看出了自己的不足,第一是数据结构方面没有以前那么熟悉了。很多知识点都遗忘了。而且编程实现方面对于细节的把握还不够。以后一定每天刷一定量的题目。多看点面试题目来巩固自己的已有知识。

题目如下:

1.二叉树的前序遍历(递归和非递归):

递归:

1
2
3
4
5
6
7
8
9
#include<iostream>
#include<stack>
using namespace std;
typedef struct Tree* Stree;
struct Tree
{
     int data;
     Stree  lchild, rchild;
};
1
2
3
4
5
6
7
8
9
10
11
12
13
void  preorder(Stree t)
 
{
 
    if (==NULL) return ;
 
    printf ( "%d" ,t->data);
 
   preorder(t->lchild);
 
   preorder(t->rchild);
 
}

非递归:

复制代码
 1 void midorder(Stree t)
 2 {
 3 stack<Stree> p;  4 if (t == NULL)return;  5 while (t || !p.empty()){  6 while (t)  7  {  8 printf("%d", t->data);  9  p.push(t); 10 t = t->lchild; 11  } 12 13 if (!p.empty()) 14  { 15 Stree s = p.top(); 16  p.pop(); 17 t = s->rchild; 18  } 19  } 20 }
复制代码

中序遍历的非递归差不多的思路,就是printf换到下边if里边,后序遍历稍微复杂点。就是只有访问完左右孩子后才会访问数据。而且要有一个指针来指示是从左孩子返回的还是右孩子返回的。

后序遍历非递归:

复制代码
 1 void postorder(Stree t)
 2 {
 3  Stree r, s;  4 stack<Stree> p;  5 while (t || p.empty())  6  {  7 if (t)  8  {  9  p.push(t); 10 t = t->lchild; 11  } 12 else 13  { 14 s = p.top(); 15 if (s->rchild&&s->rchild != r)t = s->rchild; //如果右子树已经访问过,r就指向当前节点的右子树。没有访问过就访问 16 else{ //已经访问过右孩子就可以访问节点数据了 17 printf("%d",s->data); 18  p.pop(); 19 r = s; //把r指向访问过数据的右孩子 20 t = NULL; //继续访问队尾元素。如果不置为空就会接着访问原来访问过的分支 21  } 22  } 23  } 24 }
复制代码

 2.为什么要有中断:它是计算机可以更好更快利用有限的系统资源解决系统响应速度和运行效率

中断:中断是指在计算机执行期间,系统内发生任何非寻常的或非预期的急需处理事件,使得CPU暂时中断当前正在执行的程序而转去执行相应的事件处理程序。待处理完毕后又返回原来被中断处继续执行或调度新的进程执行的过程。

3.堆排序:

猜你喜欢

转载自www.cnblogs.com/luoshiyong/p/11963963.html
今日推荐