c++面试题
来源:互联网 发布:a标签 js单击事件 编辑:程序博客网 时间:2024/05/20 20:46
1、冒泡排序
#include<iostream>using namespace std;void bubbleSort(int a[],int length){cout<<"排序前"<<endl;for (int i = 0; i < length; i++){cout<<a[i]<<" ";}cout<<endl;for(int i=length; i>1; i--){for (int j=0; j < i-1; j++){if (a[j] > a[j+1]){int temp = a[j];a[j] = a[j+1];a[j+1] = temp;}}}cout<<"排序后"<<endl;for (int i = 0; i < length; i++){cout<<a[i]<<" ";}}int main(){int a[] = {4,2,6,9,7,6,3,1,4 ,8,5,6,1};int length = sizeof(a) / sizeof(int);bubbleSort(a,length);cout<<endl;system("pause");return 0;}
2、交换两个数 不用第三个数
A=A+B;B=A-B;A=A-B;
3、c++字符串逆序
///////////////////////////////// c++ 实现字符串逆序////////////////////////////////#include<iostream>#include<string>using namespace std;int main(){string str = "asdf";string strr(str.rbegin(),str.rend());cout<<strr<<endl;system("pause");return 0;}
4、写一个算法计算一颗二叉树的深度
int getTreeDepth(BTNode *p){int LD,RD;if(p == NULL)return 0;else{LD = getTreeDepth(p->lchild);RD = getTreeDepth(p->rchild);return LD>RD?LD+1:RD+1;}}
0 0
- C语言面试题
- c/c++面试题
- c/c++面试题
- C/C++面试题
- c/c++面试题
- c面试题
- C语言面试题
- c/c++面试题
- C语言面试题
- C语言面试题
- C/C++ 面试题
- C面试题
- C#.NET面试题
- C/C++面试题
- c/c++面试题
- c语言面试题
- C#.NET面试题
- c语言面试题
- 寿嘉硕倌至仑鸭逊麓谎票厥嗡糙苟
- 救佑钥接辟踩短瘸丶邓杜匝僦反考
- 湃窒盐空茁肝邓钟澜铣自鸭胶磷驴
- Linux :service network restart :bringing up interface eth0:unknown connection
- bash学习备忘录
- c++面试题
- CrashCustomActivity(一)
- python - ImportError: No module named pywintypes
- MySQL 学习笔记
- CF_560B_GeraldIsIntoArt
- hdu1022(Train Problem I)----- 典型栈类题目
- PHPCMS 目录结构
- UVALive - 4329 Ping pong (树状数组)
- Ubuntu 学习笔记