算法
lzaiwei
简简单单 轻轻松松
展开
-
奇偶调整
一串长数字,把奇数放在前半部分偶数放在后半部分定义两个指针,一个指向开头,一个指向结尾,指针移动,若前部指针指向出现偶数 后半部分出现奇数,互换数字,直到两个指针相等;...原创 2018-03-21 23:30:44 · 263 阅读 · 0 评论 -
求二元查找树的镜像
#include using namespace std; //创建树结构 typedef struct node { int data; struct node *ltree,*rtree; }*BitTree,bitTree; //创建树函数 void creat_tree(BitTree &tree); void MirrorRecursively(BitTree &pNode);翻译 2014-09-02 15:13:30 · 305 阅读 · 0 评论 -
第一个只出现一次的字符
#include #include using namespace std; char OutOnceTimes(string str); int main() { string str; cin>>str; char OnceTime=OutOnceTimes(str); system("pause"); return 0; } char OutOnceTimes(stri翻译 2014-09-02 16:21:39 · 304 阅读 · 0 评论 -
排序数组中和为给定值的两个数字
#include #include #include using namespace std; class Solution { public: vector twoSum(vector &numbers, int target) { vector > temp; for( unsigned int i=0; i<numbers.size(); ++i ) { pai原创 2014-09-02 12:41:01 · 290 阅读 · 0 评论 -
二元查找树的后序遍历结果
#include using namespace std; bool Veri_BST(int data_in[],int length); int main() { int n; cin>>n; int *data_in=new int[n]; //输入数组 for (int i=0;i>data_in[i]; } bool ver=Veri_BST(data_in,n);翻译 2014-09-01 11:15:41 · 320 阅读 · 0 评论 -
翻转句子中单词的顺序
#include #include using namespace std; void ReverseStr(char* str_in,char* str_out); void Reverse(char *pBegin,char *pEnd); int main() { char* str_resever="I am a student"; char* str_return="";翻译 2014-09-01 20:04:18 · 287 阅读 · 0 评论 -
查找最小的k个元素
#include #include #include #include #include using namespace std; typedef multiset> HeapMax; //获取k个最小的数 void Min_Num(unsigned int k,HeapMax& Heap_Max,vector &Data_vector); int main() { std::vector翻译 2014-09-01 10:38:18 · 287 阅读 · 0 评论 -
面试
1. 异步通信和同步通信的区别? 同步通信与异步通信区别: 1.同步通信要求接收端时钟频率和发送端时钟频率一致,发送端发送连续的比特流;异步通信时不要求接收端时钟和发送端时钟同步,发送端发送完一个字节后,可经过任意长的时间间隔再发送下一个字节。 2.同步通信效率高;异步通信效率较低。 3.同步通信较复杂,双方时钟的允许误差较小;异步通信简单,双方时钟可翻译 2014-08-17 22:00:29 · 324 阅读 · 0 评论 -
在O(1)时间删除链表结点
直接把需要删除的指针指向的下一个翻译 2014-08-16 20:50:00 · 310 阅读 · 0 评论 -
求二元查找树的镜像
#include #include using namespace std; //创建树结构 typedef struct node { int data; struct node *ltree,*rtree; }*BitTree,bitTree; //创建树函数 void creat_tree(BitTree &tree); void MirrorRecursively(BitTree翻译 2014-09-02 15:14:11 · 275 阅读 · 0 评论 -
圆圈中最后剩下的数字
#include using namespace std; typedef struct LinkNode { int data_in; LinkNode *next; }; LinkNode* LasterNum(LinkNode *node,int m); int main() { LinkNode *node,*head; node=new LinkNode; head=n翻译 2014-09-02 19:31:49 · 282 阅读 · 0 评论 -
Add Two Numbers
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *addTw原创 2014-09-02 22:54:45 · 561 阅读 · 0 评论 -
MOTO面试题
1.介绍一下STL,详细说明STL如何实现vector。 答:STL 是 Standard Template Libary 的,翻译成中文叫做标准模版库. 它是是容器,算法和迭代器的集合.通过迭代器作为桥梁将容器和算法 联系起来.容器是用来存储数据的,算法是用来操作数据的.容器是模版化 的数据集和,算法是泛形化的数据操作.利用 STL 进行开发转载 2014-08-16 18:26:23 · 591 阅读 · 0 评论 -
把字符串转换成整数[算法]
#include #include using namespace std; long long CharToInt(char *str); int g_valid; enum Valid_str { Valid=0, Invalid }; int main() { char *ch="-1232324324324"; long long num=CharToInt(ch); s翻译 2014-09-03 12:37:58 · 411 阅读 · 0 评论 -
反转链表[数据结构]
#include using namespace std; struct NodeLink { int data_in; NodeLink *next; }; NodeLink *Rever(NodeLink *node); int main() { NodeLink *head,*Node,*temp; int data_in; cin>>data_in; Node=new No原创 2014-09-03 13:48:55 · 339 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
#include #include using namespace std; class Solution { public: int lengthOfLongestSubstring(string s) { int length_substr=0; int temp=0; int hashTable[256]; int i=0; while (i!=256) {原创 2014-09-02 22:51:56 · 293 阅读 · 0 评论 -
从上往下遍历二元树
#include #include #include using namespace std; //创建树结构 typedef struct node { int data; struct node *ltree,*rtree; }*BitTree,bitTree; //创建树函数 void creat_tree(BitTree &tree); void PrintFromTopToB翻译 2014-09-02 15:26:42 · 447 阅读 · 0 评论 -
链表中倒数第k个结点
#include using namespace std; typedef struct NodeLink { int data_in; NodeLink *next; }; NodeLink* EndK(NodeLink *Node,int k); int main() { NodeLink *node=NULL,*head,*temp; int data_in; node=翻译 2014-09-02 12:35:49 · 311 阅读 · 0 评论 -
O(logn)求Fibonacci数列[算法]
#include #include using namespace std; //定义2*2矩阵 struct Mxtri2 { Mxtri2(long long m00=0,long long m01=0,long long m10=0,long long m11=0) { m_00=m00; m_01=m01; m_10=m10; m_11=m11; } long翻译 2014-09-03 10:35:58 · 409 阅读 · 0 评论 -
用两个栈实现队列[数据结构]
#include #include using namespace std; void StackToQueue(void); int main() { StackToQueue(); system("pause"); return 0; } //实现stack to queue void StackToQueue() { stack temp1; stack temp2; i原创 2014-09-03 13:02:36 · 293 阅读 · 0 评论 -
在字符串中删除特定的字符
例如在 ”They are students.”删除”aeiou”翻译 2014-08-16 22:16:45 · 401 阅读 · 0 评论 -
翻转
abcfefg 2 fgabcfe 1、先把需要转的保存下来再翻转原创 2014-08-15 20:32:43 · 329 阅读 · 0 评论 -
从尾到头输出链表
1、直接链表反转 2、申请e翻译 2014-08-16 20:47:13 · 268 阅读 · 0 评论 -
旋转数组的最小元素
{3, 4, 5, 1, 2}为{1, 2, 3, 4, 5}的旋转 1、dingyi原创 2014-08-21 19:09:59 · 244 阅读 · 0 评论 -
复杂链表的复制
1、先建立单链表;从开始判断指向的dia翻译 2014-08-21 20:42:34 · 303 阅读 · 0 评论 -
对称子字符串的最大长度
1、例如判断aAa,如果A是,那么aAa是; 2、首先从中心翻译 2014-08-21 19:38:23 · 327 阅读 · 0 评论 -
C++面试
题目(一):我们可以用static修饰一个类的成员函数,也可以用const修饰类的成员函数(写在函数的最后表示不能修改成员变量,不是指写在前面表示返回值为常量)。请问:能不能同时用static和const修饰类的成员函数? 分析:答案是不可以。C++编译器在实现const的成员函数的时候为了确保该函数不能修改类的实例的状态,会在函数中添加一个隐式的参数const this*。但当一个成员翻译 2014-08-22 19:21:55 · 253 阅读 · 0 评论 -
数组中出现次数超过一半的数字
1、先排序,再查看个数; 2、hashtable,jiez翻译 2014-08-21 19:54:56 · 280 阅读 · 0 评论 -
二元树的深度
#include using namespace std; //创建树节点结构体 typedef struct TreeNode { int data_in; TreeNode *m_left; TreeNode *m_right; }*BitTree,bitTree; //树高度 int TreeHight(BitTree &bittree); //创建树节点 void Creat原创 2014-09-05 17:31:38 · 445 阅读 · 0 评论 -
和为n连续正数序列
#include using namespace std; int CountN(int number); int main() { int m=5; int count_n=CountN(m); system("pause"); return 0; } int CountN(int number) { int number1=1; int number2=2; int c原创 2014-09-05 16:56:22 · 306 阅读 · 0 评论 -
栈的push、pop序列
#include #include using namespace std; bool StackPop(int *p1,int *p2,int length); int main() { int p1[]={1,2,3,4,5}; int p2[]={4,5,3,3,1}; bool xx=StackPop(p1,p2,5); system("pause"); return原创 2014-09-05 16:19:25 · 424 阅读 · 0 评论 -
n个骰子的点数
把骰子分成两堆1和n-1,再把n-1分成1和n-2,递归,翻译 2014-08-21 19:16:18 · 280 阅读 · 0 评论 -
最长公共子串
输入两个字符串BDCABA和ABCBDAB,字符串BCBA和BDAB都是是它们的最长公共子串; 先介绍LCS问题的性质:记Xm={x0, x1,…xm-1}和Yn={y0,y1,…,yn-1}为两个字符串,而Zk={z0,z1,…zk-1}是它们的LCS,则: 1. 如果xm-1=yn-1,那么zk-1=xm-1=yn-1,并且Zk-1是Xm-1和Yn-1的LCS;原创 2014-08-21 18:46:37 · 321 阅读 · 0 评论 -
把数组排成最小的数
// Maxinum int number has 10 digits in decimal system const int g_MaxNumberLength = 10; // String buffers to combine two numbers char* g_StrCombine1 = new char[g_MaxNumberLength * 2 +翻译 2014-08-21 19:02:55 · 314 阅读 · 0 评论 -
判断整数转化为2进制之后1的个数
1、直接跟1 &,然后在右移, 缺点负数原创 2014-08-15 20:08:50 · 339 阅读 · 0 评论 -
两链表的第一个公共结点
1、判断长度之差,假设为m,长的链表先走m步,然后翻译 2014-08-16 21:01:00 · 256 阅读 · 0 评论 -
数组中只出现一次的数字
对所有数据进行异或操作,翻译 2014-08-16 20:54:55 · 274 阅读 · 0 评论 -
大数据处理
方法主要是: 分而治之/hash映射 + hash统计 + 堆/快速/归并排序; 双层桶划分; Bloom filter/Bitmap; Trie树/数据库/倒排索引; 外排序; 分布式处理之Hadoop/Mapreduce;翻译 2014-08-16 19:45:20 · 400 阅读 · 0 评论 -
子数组的最大和[算法]
#include #define LENG 10 using namespace std; int Max_num(int max_num[],int leng); int main() { int data_in[LENG]; int max_data=0; for (int i=0;i>data_in[i]; } max_data=Max_num(data_in,LENG);原创 2014-08-28 21:53:13 · 293 阅读 · 0 评论 -
跳台阶
对以有一步的情况,只有一种情况,即只跳一步原创 2014-08-15 20:13:32 · 249 阅读 · 0 评论