C++
lzaiwei
简简单单 轻轻松松
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
整数二进制表示中1的个数
#include using namespace std;int BitOneNumbers(int i);int main(){ int i; cin>>i; int numbers=BitOneNumbers(i); system("pause"); return 0;}int BitOneNumbers(int i){ int counts=0; wh原创 2014-09-05 15:40:08 · 365 阅读 · 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 · 338 阅读 · 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 · 356 阅读 · 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 · 632 阅读 · 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 · 479 阅读 · 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 · 409 阅读 · 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 · 347 阅读 · 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 · 329 阅读 · 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 · 338 阅读 · 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 · 462 阅读 · 0 评论 -
用两个栈实现队列[数据结构]
#include #include using namespace std;void StackToQueue(void);int main(){ StackToQueue(); system("pause"); return 0;}//实现stack to queuevoid StackToQueue(){ stack temp1; stack temp2; i原创 2014-09-03 13:02:36 · 371 阅读 · 0 评论 -
高质量c++/c编程指南--其它编程经验
1、指针或者引用传递用作输出,不能用const修饰,或者失去输出功能;2、参数是指针,用const修饰,防止修改;值传递没有必要,因其使用的是其对应的副本;3、对于非内部数据类型,例如类,使用引用,不需要产生副本调用构造函数与析构函数,可以使用const修饰,对于正常类型按值传递,不需要使用引用,因效率差不多;4、const修饰函数返回,必须使用const变量接收;对于按值返回,加上c原创 2017-03-29 16:21:04 · 218 阅读 · 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 · 365 阅读 · 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 · 495 阅读 · 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 · 356 阅读 · 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 · 482 阅读 · 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 · 367 阅读 · 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 · 495 阅读 · 0 评论 -
二叉树创建与访问
#include using namespace std;//创建数结构typedef struct node{ int data; struct node *ltree; struct node *rtree;}*BitTree,bitTree;void creat_tree(BitTree &tree);void pre_travel(BitTree &tree);v原创 2014-08-22 23:04:31 · 466 阅读 · 0 评论 -
把二元查找树转变成排序的双向链表
#include using namespace std;//创建树结构typedef struct node{ int data; struct node *ltree,*rtree;}*BitTree,bitTree;//创建树函数void creat_tree(BitTree &tree);void mid_travel(BitTree tree,BitTree &bs原创 2014-08-25 23:04:01 · 308 阅读 · 0 评论 -
设计包含min函数的栈[数据结构]
#include #include #include using namespace std;template class CStackWithMin{public: CStackWithMin(){}; virtual ~CStackWithMin(){}; T& top(void); const T& top(void) const; void push(const T原创 2014-08-28 20:53:23 · 365 阅读 · 0 评论 -
子数组的最大和[算法]
#include#define LENG 10using 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 · 345 阅读 · 0 评论 -
查找最小的k个元素
#include#include #include #include#includeusing 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 · 338 阅读 · 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 · 364 阅读 · 0 评论 -
二元树中和为某一值的所有路径
#include #include using namespace std;typedef struct BitTree{ int data; struct BitTree *m_pLeft,*m_pRight;}*NodeTree,nodetree;void Creat_Tree(NodeTree &tree);void FinfPath(NodeTree &path翻译 2014-09-01 09:41:55 · 346 阅读 · 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 · 333 阅读 · 0 评论 -
高质量C++/C编程指南--类的继承与组合
1、面向对象热点COM和CORBA;2、不相干的比继承,逻辑相关则继承;3、若在逻辑A是B的一部分,不允许B从A派生,用A和其它组合出B;原创 2017-03-29 16:27:25 · 236 阅读 · 0 评论
分享