- 博客(42)
- 资源 (6)
- 收藏
- 关注
原创 scp.exp脚本:scp命令自动输入密码
#### 1.scp.exp用法(以ubuntu为例):- sudo apt-get install expect- expect scp.exp 127.0.0.1 root passwd srcfile destfile 300#### 2.scp.exp脚本内容```bash#!/usr/bin/expect
2018-01-20 18:28:40
2066
原创 STL sort源码剖析
//sort函数源码:template <class _RandomAccessIter>inline void sort(_RandomAccessIter __first, _RandomAccessIter __last) { __STL_REQUIRES(_RandomAccessIter, _Mutable_RandomAccessIterator); __STL_REQUIRE
2015-12-10 17:16:00
608
原创 Add Binary
void addtwobits(char *sum,char a,char b,int *carry){ *sum=(((a-'0')+(b-'0')+*carry)&0x01)+'0'; *carry=((a-'0')+(b-'0')+*carry)>>1;}void revert(char *a,int *len){ int i=0; *len=strl
2015-08-18 09:08:19
564
原创 echo
#include#include#include#include#include#include#include#include#include#include#include#define MAX_EVENT_NUM 1024#define TCP_BUFFER_SIZE 512#define UDP_BUFFER_SIZE 1024int setnonblock
2015-08-15 21:17:50
529
原创 socket可读/可写
在网络编程中,下列情况socket可读: 1,socket内核缓存区中字节数大于或等于其低水位标记SO_RCVLOWAT。 2,socket通信的对方关闭连接。此时对该socket的读操作将返回0. 3,监听socket上有新的连接请求。 4,socket上有未处理的错误。下列情况socket可写: 1,socket内核缓存区中的可用字节数大于
2015-08-15 18:56:32
1078
原创 Insertion Sort List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* in
2015-07-29 14:28:56
623
原创 Search for a Range
/** * Return an array of size: *returnSize. * Note: The returned array must be malloced, assume caller calls free(). */int* searchRange(int* nums, int numSize, int target, int* returnSize) { *r
2015-07-28 20:12:50
496
原创 git总结
1,初次运行 Git 前的配置Git 提供了一个叫做 git config 的工具,专门用来配置或读取相应的工作环境变量。而正是由这些环境变量,决定了 Git 在各个环节的具体工作方式和行为。这些变量可以存放在以下三个不同的地方:• /etc/gitconfig 文件:系统中对所有用户都普遍适用的配置。若使用 git config 时用 --system 选项,读写的就是这个文件。
2015-07-16 09:39:37
420
原创 Makefile总结
sf:=$(wildcard ./src/*.cpp)of:=$(patsubst %.cpp,%.o,$(sf))sfx:=$(wildcard ./src/rand-utils/*.cpp)ofx=$(patsubst %.cpp,%.o,$(sfx))of+=$(ofx)./bin/grw:$(of) g++ -o $@ $^ $(of):%.o:%.cpp g++ -c $
2015-07-15 10:19:50
425
原创 Search a 2D Matrix
//https://leetcode.com/problems/search-a-2d-matrix/bool searchMatrix(int** matrix, int matrixRowSize, int matrixColSize, int target) { int i=matrixRowSize-1;//行; int j=0;//列; while((i>
2015-07-12 20:15:28
390
原创 Valid Phone Numbers
https://leetcode.com/problems/valid-phone-numbers/# Read from the file file.txt and output all valid phone numbers to stdout.awk '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/{print $0}' fi
2015-07-11 13:26:01
870
原创 Word Frequency
https://leetcode.com/problems/word-frequency/# Read from the file words.txt and output the word frequency list to stdout.awk '{for(i=1;i<=NF;i++){arr[$i]++}} END{for(w in arr){print w" "arr[w]}}
2015-07-11 12:59:37
525
原创 tar&&gzip&&zip
//参考《 Linux Shell 脚本攻略 第二版》tar命令中的-c 代表“create file”tar命令中的-f 代表“specify filename”。(文件名必须紧跟在-f之后,而且-f应该是选项中的最后一个)1,用tar对文件进行归档:ubuntu@VM-62-13-ubuntu:~$ tar -cf all.tar all all~ubuntu@VM
2015-06-29 21:03:47
726
原创 diff&&patch
1, diff -u用于一体化输出:ubuntu@VM-62-13-ubuntu:~$ diff -u v1 v2--- v1 2015-06-27 20:43:50.530653196 +0800+++ v2 2015-06-27 20:43:53.530653196 +0800@@ -1,7 +1,7 @@ 4 3 2-5+4 7 7-8+ubuntu@VM-
2015-06-27 20:44:40
755
原创 head&&tail
//参考《Linux shell脚本攻略 第2版》1,heada)打印前10行:ubuntu@VM-62-13-ubuntu:~$ head fileb)打印前5行:ubuntu@VM-62-13-ubuntu:~$ head-n 5 file 或者ubuntu@VM-62-13-ubuntu:~$ head-5 file c)打印除了最后M行之外的所有
2015-06-27 14:24:20
875
原创 链表快排
#include#includetypedef struct list{ int data; struct list *next;}list;void swap(int *a,int *b){ int temp=*a; *a=*b; *b=temp; return;}list* partition(list *head, list
2015-05-16 16:59:25
578
原创 反转链表(递归实现)
反转链表#includestruct ListNode{ int m_nKey; struct ListNode* m_pNext;};void ReverseList(struct ListNode** pHead){ struct ListNode *ReverseHead=NULL; struct ListNode *pNode=*pHead;
2015-05-16 16:58:47
707
原创 C++对象作为函数参数
关于C/C++中基本类型(如:int,int*等)作为函数参数时,是通过将该变量的值压栈来进行参数传递;本文通过C++反汇编代码分析了当对象作为函数参数时(该形参非引用或指针),参数如何传递以及此时栈帧的结构。
2014-08-20 08:58:04
3004
原创 qsort对动态二维数组进行排序
1,关于网上对于qsort函数对一维数组,二维数组(即字符串,形如char ch[2][6];strcpy(ch[0],"Hello");strcpy(ch[1],"World"); 对”Hello"和"World"排序。)的排序的介绍比较常见,本文介绍了使用qsort函数对动态二维数组(即对字符串进行排序。形如:char**p=new char*[2]; p[0]=new char[6];str
2014-08-20 08:58:02
1479
原创 插入排序
点击(此处)折叠或打开 //直接插入排序 void InsertSort(int *a, int n)//下标从0开始。 { int i; for(i=1;in;i++) {
2014-08-20 08:58:00
513
原创 MFC thunk技术模拟
点击(此处)折叠或打开 //参考http://www.cnblogs.com/satng/archive/2010/12/30/2138833.html #includeiostream> using namespace std;
2014-05-26 19:08:51
634
原创 信号量P/V操作
//深入理解计算机系统1,信号量s是具有非负整数值的全局变量,只能由两种特殊的操作来处理,这两种操作称为P和V:P(s):如果s是非零的,那么P将s减1,并且立即返回。如果s为零,那么就挂起这个线程,直到s变为非零,而一个V操作会重启这个线程。在重启止呕,P操作将s减1,并将控制返回给调用者。V(s):V操作将s加1。如果有任何线程阻塞在P操作等待s变成非零,那么V操作会重启这些线
2014-05-26 19:08:47
2978
原创 二叉查找树
//数据结构与算法分析 点击(此处)折叠或打开 #ifndef __BINARYSEARCHTREE_H__ #define __BINARYSEARCHTREE_H__ //templatetypename int>
2014-05-26 19:08:44
598
转载 零长度数组的妙用
零长度是指定义数组时,指定其长度为0(如int arr[0];),这样的数组不占用实际的空间,但能通过数组名访问到其指向的地址。如下例所示:#include stdlib.h>#include stdio.h>struct device{ int num; int count; int reserve[0]; /* * reserve是一个数组名;该数组没
2014-05-26 19:08:35
440
原创 跳表的实现
图示: 点击(此处)折叠或打开 //转载 //SkipList #include stdlib.h> #include stdio.h> #includetime.h>
2014-05-26 19:08:33
550
原创 欧几里德算法
//数据结构与算法分析 点击(此处)折叠或打开 #includestdio.h> int gcd1(int m,int n)//m>=n { if(n==0)
2014-05-26 19:08:31
439
原创 求unsigned int i的二进制表示中1的个数
点击(此处)折叠或打开 //转 int fun1(unsigned int i) { if(i2) return i; else
2014-05-26 19:08:27
897
原创 大端法与小端法互换
以int类型为例: 点击(此处)折叠或打开 void swap1(int *rhs) { unsigned char *p=rhs; unsigned char temp;
2014-05-26 19:08:24
562
原创 排序
点击(此处)折叠或打开 int a[10]; n=10; ------------------------------------------------ //直接插入排序 void InsertSort(int *a, int
2014-05-26 19:08:22
417
原创 成员函数的指针
//C++ Primer 第四版1,成员指针只应用与类的非static成员。static类成员不是任何对象的组成部分,所以不需要特殊语法来指向static成员,static成员指针是普通指针。 2,成员函数的指针必须在三个方面与它所指函数的类型想匹配: A,函数的形参的类型和数目,包括成员是否为const. B,返回类型。
2014-05-26 19:08:20
467
原创 extern "C"
//C++ Primer 第四版 1,C++使用链接指示(linkage directive)指出任意非C++函数所用的语言。 2,链接指示有两种形式:单个的或复合的。链接指示不能出现在类定义或函数定义的内部,它必须出现在函数的第一次声明上。 3,声明非C++函数: extern "C" size_t strlen(const char *);
2014-05-26 19:08:18
577
原创 Mangling
C++和Java中能使用重载函数,是因为编译器将每个唯一的方法和参数列表组合编码成一个对链接器来说唯一的名字,这种编码过程叫做毁坏(mangling),而相反的过程叫做恢复(demangling)。 C++和Java使用兼容的毁坏策略。一个被毁坏的类名字是由名字中字符的整数数量,后面跟原始名字组成的,比如:类Foo被编码成3Foo.方法被编码为原始方法名后面加上_ _ ,加上被毁坏的类
2014-05-26 19:08:16
647
原创 OPERATOR NEW FUNCTION
//C++ Primer1,The library function operator new and operator delete are misleadingly named. Unlike other operator functions,such as operator=,these functions do not overload the new or delete expres
2014-05-26 19:08:14
424
原创 显示调用析构函数
//C++ Primer//显示调用析构函数的效果是适当的清除对象本身。但是,并没有释放对象所占的内存,如果需要,可以重用该内存空间。 #includeiostream> #includecstdio> using namespace std;
2014-05-26 19:08:11
849
原创 引用
//参考《C++反汇编与逆向分析技术揭秘》//在反汇编下,没有引用这种数据类型。//在C++中,引用和指针没有分别,只是引用是通过编译器实现寻址的,而指针需要手动寻址。//C++为了简化指针操作,对指针的操作进行了封装,产生了引用类型。引用类型在C++中被描述为变量的别名。实际上,引用类型就是指针类型,只不过它用于存放地址的内存空间对使用者而言是隐藏的。----- --------
2014-05-26 19:08:03
510
原创 局部静态变量的工作方式
//vc6.0 debug//cs218.cpp//参考《老码识途》//知识点:C++语法规定局部静态变量只被初始化一次,采用标志位来实现赋值操作只被执行一次(标志位为0时,表示未初始化,标志位为1时表示已初始化)。------------------------------------------------------------------------------ #
2014-05-26 19:08:01
428
原创 C++调用DLL总结
1,编写调用端代码: //main.cpp #include"VrpDll.h"//VrpDll.h放在工程的当前目录。 #include #include using namespace std; #pragma comment(lib,"CppVrpDll.lib") //CppVrpDll.lib放在工程的当前目录,Cp
2014-05-26 19:07:58
587
原创 奇怪的死循环
点击(此处)折叠或打开 //《老码识途》P083 #includestdio.h> int main() { int i; int a[1
2014-05-26 19:07:54
496
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人