摘要: 计数排序/** *@param array is the array to sort *@param length is the length of the array *@param range is the range of the whole numbers in array */void CountingSort(int* array, int length, int range){//this algorithm needs two auxiliary, one for counting the total number of the digits, one for placing 阅读全文
posted @ 2013-10-26 14:15 Wolves_群狼 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 基数排序分为从低位到高位,和从高位到低位两种。一、从低位到高位采用计数排序才完成每一趟的排序,每一趟计数排序都是对带排序数组某一位的排序。void RadixSort(int* array, int length){ int* auxiliary_array = new int[length];//for placing sorted digits int* digit_array = new int[length];//record the certain digit of the number in array for (int digit = 1; true; ++di... 阅读全文
posted @ 2013-10-26 13:54 Wolves_群狼 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 归并排序,典型的分治思想,时间复杂度为O(nlogn)。一、数组递归:void MergeSort(int* array, int low, int high, int* auxiliary_array){ if (low >= high) return; int mid = low + (high - low) / 2; MergeSort(array, low, mid, auxiliary_array); MergeSort(array, mid + 1, high, auxiliary_array); int i = low; int j = mid... 阅读全文
posted @ 2013-09-08 00:22 Wolves_群狼 阅读(175) 评论(0) 推荐(1) 编辑
摘要: 一、算法导论上的快速排序void swap(int* value1, int* value2){ int temp = *value1; *value1 = *value2; *value2 = temp;}void QuickSort(int* array, int low, int high){ if (low >= high) return; int i = low - 1; for (int j = low; j = high) return; int key = array[low];//pivot int i = low; in... 阅读全文
posted @ 2013-09-06 13:44 Wolves_群狼 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 一般的Fibonacci算法:int Fibonacci(int number){ if (number > 1), matrix); } else { return MatrixPower(MatrixMultiply(matrix, matrix), exponent >> 1); }}int Fibonacci(int number){ if (number > 1; } return result.m_00;}利用了{f(n), f(n-1), f(n-1), f... 阅读全文
posted @ 2013-09-02 20:26 Wolves_群狼 阅读(286) 评论(0) 推荐(0) 编辑
摘要: 一、尾递归 一般的递归如果递归次数过多就可能会遇到栈溢出,这是由于每个线程在执行代码时,都会分配一定尺寸的栈空间(Windows系统中为1M),每次方法调用时都会在栈里储存一定信息(如参数、局部变量、返 回地址等等),这些信息再少也会占用一定空间,成千上万个此类空间累积起来,自然就超过线程的栈空间了。不过这个问题并非无解,我们只需把递归改成如下形式即可(在这篇文章里我们不考虑非递归的解法)int Factorial(int number, int accumulator){ if (number continuation){ if (0 == number) return co... 阅读全文
posted @ 2013-09-01 00:55 Wolves_群狼 阅读(246) 评论(0) 推荐(0) 编辑
摘要: 一般的乘方算法,时间复杂度是O(n)通过下面的方式,能达到O(logn)——递归实现:int Power(int num, int exponent){ if (1 == exponent) { return num; } if (0 == exponent) { return 1; } int result = 0; if (exponent & 1) {//if exponent is odd result = num * Power(num * num, exponent >> 1); } else {/... 阅读全文
posted @ 2013-08-27 13:00 Wolves_群狼 阅读(486) 评论(0) 推荐(0) 编辑
摘要: 转载自:http://www.cnblogs.com/wu8685/archive/2010/12/21/1912347.html博主:@心灵深处 递归算法时间复杂度的计算方程式一个递归方程: 在引入递归树之前可以考虑一个例子: T(n) = 2T(n/2) + n2 迭代2次可以得: T(n) = n2 + 2(2T(n/4) + (n/2) 2) 还可以继续迭代,将其完全展开可得: T(n) = n2 + 2((n/2) 2 + 2((n/22)2 + 2((n/23) 2 + 2((n/24) 2 +…+2((n/2i) 2 + 2T(n/2i + 1)))…)))) ... 阅读全文
posted @ 2013-08-27 10:21 Wolves_群狼 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 使用Jpcap监听网卡,捕获数据包,得到mac地址,ip地址和端口号(只解析了tcp数据包): 1 import jpcap.JpcapCaptor; 2 import jpcap.NetworkInterface; 3 import jpcap.PacketReceiver; 4 import jpcap.packet.*; 5 6 public class Test { 7 public static void main(String[] args) 8 { 9 try {10 final NetworkInterfac... 阅读全文
posted @ 2013-01-18 12:21 Wolves_群狼 阅读(1238) 评论(0) 推荐(0) 编辑
摘要: 1 #include <iostream>2 3 using namespace std;4 5 int main()6 {7 cout << "hello my blog!" << endl;8 return 0;9 } 阅读全文
posted @ 2013-01-10 16:35 Wolves_群狼 阅读(123) 评论(0) 推荐(0) 编辑