随笔分类 - c/c++
c语言,算法,数据结构
摘要:以前做java项目的时候,需要一些配置参数,java提供了Properties 类 来操作,存储配置,挺方便的,现在既然在看c++,就想着用c++来实现这么一个类。 要求: 1.支持注释,单行,多行注释都行 2.简单的key/value 模型 3.获取,修改,清空,存储操作等 接口头文件:properties.h #ifndef PROPERTIES_H#define PROPERTIES_H#include <string>#include <map>namespace huals{class Properties{private //配置文件路径std::strin
阅读全文
摘要:看到上一篇博客是2012.12月份的,真是岁月如梭,这也说明自己这一段时间也真是懒惰了,唉,微博玩多了,废话不多说,上菜。 c++ 顺序存储结构 有三种:vector(数组),list(链表),deque(数组和链表一种结合,暂不清楚怎么实现的,应该是数组的变种),说说适配器的情况,适配器是在存储结构上实现的一种既定范围的操作,如队列,栈等(一般和既定的业务,目的相关)。下面就来实现一下栈的操作,上代码: 栈的接口头文件:stack.h #ifndef stack_h#define stack_h#include <deque>namespace huals{template<
阅读全文
摘要:好久没写博客了,博客荒废了,人也废了,c++ primer果然经典,看了之后明白了许多之前不懂得细节。 当定义一个新类型的时候,需要显示或隐式地指定复制,赋值和撤销该类型的对象时会发生什么---这是通过定义特殊成员:复制构造函数、赋值操作符重载和析构函数来达到的。如果没有显示定义这些,编译器会为我们实现。 之前学习c++语言时大家知道函数参数传递方式有两种,值传递和引用传递。值传递开始自己理解为就是拷贝,但是执行的是什么拷贝?=号函数还是拷贝构造函数,答案是拷贝构造函数。函数返回值时编译器会创造一个临时变量,执行的也是拷贝构造函数。View Code #include <iostream
阅读全文
摘要:平衡二叉树是这样一棵树:它是一棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二叉树。查找、插入和删除在平均和最坏情况下都是O(log n)。可以用于数据库设计,内存分配算法等。/*平衡二叉查找树written by huals2012.10.13*/#include <stdio.h>#include <stdlib.h>typedef struct BSTreeNode{int value;struct BSTreeNode *left;struct BSTreeNode *right;struct BSTreeNode *parent
阅读全文
摘要://散列表之链表散列#include <stdio.h>#include <string.h>#include "linux_list.h"#define m 7struct record{struct list_head list;int id;char name[10];};int Record_value(char *str,struct record *rec);int main(void){int i,j,n;struct list_head *hash;char str[100];FILE *fp;struct record *a;has
阅读全文
摘要:#include <stdio.h>void merge(int *const a,int p,int q, int r);void merge_sort(int a[],int p,int r);int main(void){int j;int arraynumber[]={3,5,1,2,0,-1,-3,7,9,8};int len=sizeof(arraynumber)/sizeof(int);merge_sort(arraynumber,0,len-1);for(j=0;j<len;j++)printf("%d\n",arraynumber[j])
阅读全文
摘要:#include <stdio.h>void sort( int * const arraynumber,int len);int main(void){int j;int arraynumber[]={3,5,1,4,2,9,4,6,3,8,7,0};int len=sizeof(arraynumber)/sizeof(int);sort(arraynumber,len);for(j=0;j<12;j++)printf("%d\n",arraynumber[j]);return 0;}void sort(int *const arraynumber,in
阅读全文
摘要:#include <stdio.h>void sort( int * const arraynumber,int len,int *head);int main(void){int j;int arraynumber[]={3,5,1,4,2,9,4,6,3,8,7,0,-1,-3};int len=sizeof(arraynumber)/sizeof(int);int sortarray[len];sort(arraynumber,len,sortarray);for(j=0;j<len;j++)printf("%d\n",sortarray[j]);r
阅读全文
摘要:#include <stdio.h>struct node{ int number; struct node * next;};void Init_list(struct node *root);void Push_list(struct node *p,struct node *root);void Pop_list(struct node *root);struct node* Get_list(struct node *root);void Print_list(struct node *root);int main(void){ struct node head,a,...
阅读全文
浙公网安备 33010602011771号