code---c++
文章平均质量分 54
zhou753099943
脚步一直不会停
展开
-
顺序表的实现
顺序表的实现 我也是正在学链表,所以就按自己的想法把顺序表的基本实现功能写出来分享给大家, 希望对你有帮助。1:头文件list.h#ifndef _LIST_H_#define _LIST_H_#include#include#define ElemType int#define error -1typedef struct List{ size_t size;原创 2015-04-28 21:17:16 · 488 阅读 · 0 评论 -
哈希表C++实现--hash_table
1、hash_table.h#include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 struct table_node 10 { 11 int _key; 12 string _value; 13 struct tabl原创 2016-05-31 10:57:49 · 5580 阅读 · 2 评论 -
linux ATM自定取款机简单实现
首先是在linux地下实现的,创建了四个文件,主要实现流程:注册-登陆-存款-取款-转账-更改密码-查询个人信息-显示全部账户-退出系统废话不多说,直接看代码:Blank.h#include #include #include #include #include #include #include #include using namespace std;#原创 2016-05-08 10:23:31 · 3207 阅读 · 1 评论 -
双链表插入 删除详解
节点结构:struct both_node{ int key; struct both_node *prev; struct both_node *next; both_node(int k) :key(k),prev(NULL),next(NULL) {}};不带头节点的双链表实现插入 删除,双链表//插入void insert_both(both_no原创 2016-06-07 18:09:49 · 4490 阅读 · 0 评论 -
memcpy优化 实现高效
1:函数原型void * memcpy ( void * des, const void * src, size_t size );它是实现对内存的拷贝,所以还是很高效的,我这里没有考虑字符重叠的情况,只是实现它的高效性,废话不多说直接上代码1 2 #include 3 #include 4 using namespace std; 5 6 void* Me原创 2016-06-04 18:33:36 · 10585 阅读 · 2 评论 -
AVL树详解
AVL树C++代码实现1、源文件tree.h1 2 #include 3 using namespace std; 4 5 template 6 struct TreeNode 7 { 8 T data; 9 T df; 10 struct TreeNode *leftchild,*rightchild; 11 Tr原创 2016-05-31 10:50:34 · 396 阅读 · 0 评论 -
智能指针详解
重点:学习智能指针,看这偏博客就够了,讲得很详细,特别用心去写的博客原文出自:http://www.cnblogs.com/Lynn-Zhang/p/5699983.html博客园首页新随笔管理随笔 - 48 文章 - 2 评论 - 5智能指针 auto_ptr、scoped_ptr、shared_pt转载 2016-09-02 11:27:21 · 4607 阅读 · 0 评论 -
求数组(元素可为正数、负数、0)的最大子序列和。
int max_sum(int *arr,int len){ assert(arr); assert(len > 0); int sum=0; int key=-INT_MAX; for(int i=0; i<len; ++i) { if(sum <= 0) sum=arr[i]; else sum+=arr[i]; if(sum >= key)原创 2016-08-14 12:56:59 · 1518 阅读 · 0 评论 -
二叉搜索树C++实现
1、二叉搜索树Bin_Search_tree.h1 2 #include 3 using namespace std; 4 5 template 6 struct BSTNode 7 { 8 T data; 9 BSTNode *leftchild,*rightchild; 10 BSTNode(const T d=T()) 1原创 2016-05-31 10:54:08 · 432 阅读 · 0 评论 -
二叉树非递归实现
//FBinTree.h#pragma once#includeusing namespace std;#includetemplateclass BinTree;templateclass BinTreeNode;typedef enum{L,R}Tag_Type;templatestruct Node{ Tag_Type Falg; BinTreeNode原创 2016-03-28 18:21:42 · 509 阅读 · 0 评论 -
递归实现字符串反转
#includeusing namespace std;void Swap(char &a,char &b){ char ch=a; a=b; b=ch;}void reverse(char *str,int low,int higth){ if(low<higth) { Swap(str[low],str[higth]); reverse(str,low+1,hi原创 2016-03-28 18:02:25 · 1609 阅读 · 0 评论 -
链式栈的基本操作与实现
1:头文件:SqStack.h#include#include#define ElemType int#define STACK_SIZE 100#define ADD_SIZE 10typedef struct SqStack{ ElemType *base; ElemType *top; int stacksize;}SqStack;bool Isempty(SqSt原创 2015-05-17 12:17:21 · 1134 阅读 · 0 评论 -
位运算实现两个数的加法
#includeint add(int a,int b){ if(b==0) return a; int sum,ret; sum=a^b; ret=(a & b)<<1; return add(sum,ret);}void main(){ int a=4; int b=5; int sum=0; sum=add(a,b); printf("%d\n",sum);原创 2015-06-12 17:51:32 · 1342 阅读 · 0 评论 -
error C2143: syntax error : missing ';' before '}'
1:错误的代码class name{private: int m_a;public: name(int a=0):m_a(a){}};void main(){ name *p[]={new name,new name};}然后出现的错误提示:error C2143: syntax error : missing ';' before '}'2:更正的代码:cla原创 2015-08-05 13:35:40 · 900 阅读 · 1 评论 -
String构造函数 拷贝构造函数 析构函数 赋值构造函数的实现
标题:String函数的实现-->主要实现构造函数,拷贝构造函数,析构函数,赋值构造函数。这几个函数是字符串函数最基本的函数,今天也总结一下#includeusing namespace std;#includeclass MyString{private: char *str;public: MyString(const char *pStr)//构造函数 { if(原创 2015-10-21 21:30:08 · 2065 阅读 · 0 评论 -
快速排序
用了模板来实现的快速排序,思想是:先选一个随机的值作为关键值,然后让地位和高位的分别和它进行比较,把比它小的都放在它的前面,比它大的都放在后面,然后递归的实现!#includeusing namespace std;templatevoid print(Type *arr,int length){ for(int i=0;i<=length;++i) { cout<<arr[原创 2015-09-19 21:35:20 · 502 阅读 · 0 评论 -
数据结构_不带头结点的链表逆制
1:以前写的都是带有头节点的链表的逆制,其思想是:把头节点后的后一个节点摘下来进行头插就可以了,实现的方法也不难,只需要两个指针就可以实现,而我这主要实现的是不带头节点的链表,而且时间复杂度位O(n),也是需要两个指针来实现,具体看代码:2:sort.h-->头文件#includeusing namespace std;///链表typedef struct Node{ i原创 2015-10-26 19:22:52 · 1571 阅读 · 0 评论 -
笔试题:输入0123456789对应输出“一二三四五六七八九”
题目描述:当输入一个数的时候:即输入:1,对应输出:一;输入:2,对应输出:二当输入两个数的时候:即输入:12;输出:一十二;输入:10,输出:一十当输入三位数的时候:即输入:123,输出:一百二十三;输入:100,输出:一百等等这是完美世界的一道在线笔试题,当时时间不够,没能完全做完,想想真是遗憾,话不多说了直接上代码 2 #include 3 #include 4 #i原创 2016-04-26 13:03:15 · 6555 阅读 · 0 评论 -
找出给定字符串中数字字符 (即’0’—‘9’这10个数字)的个数
#includeusing namespace std;/*写一个函数,找出给定字符串中数字字符(即’0’—‘9’这10个数字)的个数(如字符串”olympic2000”中数字字符的个数为4个。函数的原型为:int CalcDigital(char *str);*/int CalcDigital(char *str){ if(str==NULL) return 0; i原创 2016-03-28 18:00:43 · 5449 阅读 · 0 评论 -
将字符串中的所有空格去掉,要求时间复杂度O(N)
//题目:将字符串中的所有空格去掉,要求时间复杂度O(N)//空间复杂度O(1)//感想:最开始我以为这个题目很简单,但面试的时候由于紧张,没有写得特别优化,所以被小米给刷了,贼伤心的//条件的控制很重要,我当时就是因为紧张,条件没有控制好,现在想想真是很尴尬,//面试出来后我都有一种想法我他妈就不适合当程序员#include using namespace std;#include原创 2016-09-30 17:21:05 · 2865 阅读 · 0 评论