创新工场笔试题--笔试地点:华南理工大学
2009-10-21 17:10
239 查看
#include<iostream> #include<string> #include<math.h> using namespace std; struct node { int key; node *left; node *right; }; node* buildTree(node* head,int value); void showTree(node* head); int main() { /* //第一题:将输入的一句英文句子按单词逆序输出。例如: //输入:I love python //输出:python love I string s[1000]; int size = 0; string t; while(cin>>t) { s[size] = t; size++; } for(int i = size;i >= 0;--i) cout<<s[i]<<" "; cout<<endl; */ /* //第二题:随便输入一个正整数,输出比它大的最小质数。例如: //输入:9 //输出:11 int num = 0; cin>>num; while(1) { ++num; int mark = 0; for(int i = sqrt((float)num);i >= 2;--i) if(num % i == 0) { mark = 1; break; } if(0 == mark) { cout<<num<<endl; break; } else continue; } */ //第三题:任意给定一个整形数组,基于数组建立一棵二叉排序树,要求左子树所有节点比根小,右子树所有节点比根大。 int arr[10] = {16,14,18,10,12,20,9,17,15,19}; for(int j = 0;j != 10;++j) cout<<arr[j]<<" "; cout<<endl; int i = 0; node* Head = NULL; while(i != 10) { Head = buildTree(Head,arr[i]); ++i; } showTree(Head); cout<<endl; return 0; } node* buildTree(node* head,int value) { node* p = new node; p->key = value; p->left = p->right = NULL; if(NULL == head) return p; else { if(p->key < head->key) head->left = buildTree(head->left,value); else head->right = buildTree(head->right,value); return head; } } void showTree(node* head) { if(head->left != NULL) showTree(head->left); cout<<head->key<<" "; if(head->right != NULL) showTree(head->right); }
相关文章推荐
- 2013 创新工场笔试题
- 创新工场笔试题整理
- 创新工场笔试、小米科技笔试、百度笔试 研发部门
- 创新工场笔试题整理
- 9月24日百度校园招聘运维职位笔试地点
- 创新工场09.10.21笔试(广州)
- 创新工场2014笔试算法题汇总
- 创新工场笔试题目
- 创新工场笔试题2014 校园招聘 ---武汉站
- 09-25 创新工场笔试 位操作 题
- 【面试笔试-c/c++】2013年校园招聘创新工场笔试题(北邮场)
- 创新工场笔试题
- 算法题3:二叉树度为0的结点个数(创新工场笔试题)
- 2014年9月创新工场校招笔试题
- 创新工场笔试
- 2014创新工场笔试题
- [2014创新工场笔试]求一个正数的开方,不能使用库函数sqrt,精度在0.001以内即可
- 9.19 创新工场宣讲会+笔试
- 创新工场笔试题2013年校园招聘
- 创新工场 笔试1