自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

说自己行就行

专注互联网知识

  • 博客(12)
  • 资源 (1)
  • 收藏
  • 关注

转载 排序算法的稳定性

这几天笔试了好几次了,连续碰到一个关于常见排序算法稳定性判别的问题,往往还是多选,对于我以及和我一样拿不准的同学可不是一个能轻易下结论的题目,当然如果你笔试之前已经记住了数据结构书上哪些是稳定的,哪些不是稳定的,做起来应该可以轻松搞定。本文是针对老是记不住这个或者想真正明白到底为什么是稳定或者不稳定的人准备的。      首先,排序算法的稳定性大家应该都知道

2015-05-20 21:23:59 429

原创 左移右移的优先级不要再弄错了

int mid = low+((high-low)>>1);千万不要写成    int mid = low+(high-low)>>1;因为+、-的优先级比>>、

2015-05-20 16:59:18 1474 1

原创 用快速排序法寻找第k大元素

#include#include#include#includeusing namespace std;// 求首元素、中间元素和尾元素的中位数,将中位数与首元素交换位置inline void medianAsPivot(int arr[], const int& left, const int& right){ const int middle = left+(right

2015-05-19 20:52:50 2521

原创 快速排序(取中位数法)

#include#include#includeusing namespace std;// 求首元素、中间元素和尾元素的中位数,将中位数与首元素交换位置inline void medianAsPivot(int arr[], const int& left, const int& right){ const int middle = left+(right-left)>>1

2015-05-19 17:44:23 8229

原创 Determine if a string has all unique characters

Problem:高效率实现“字符串中是否有重复字符”Implement an algorithm to determine if a string has all unique characters. What if youcan not use additional data structures?#include#include#include#include#include#include#incl

2015-05-19 10:28:45 653

原创 对字符串进行排序,学会使用仿函数

#include#include#include#includeusing namespace std;bool myCompare(char a, char b){ return a>b;}struct myCompare2{ bool operator()(char a, char b) { return a>b; }};

2015-05-19 09:41:19 902

原创 用memset对非字符型数组初始化可能会出现错误

功能:memset是对一个一个的字节进行初始化。有可能出错的地方: 如果对int数组进行初始化为非0的整数,会出现错误,如:memset(arr, 1, sizeof(int)*length)每个数都被初始化为00000001 00000001 00000001 00000001。而不是1#include#include#include#includeusing namespace

2015-05-18 14:26:47 899

原创 面向“ACM等比赛中的测试用例”的重定向问题

#include#include#includeusing namespace std;int main(){    ifstream ifile("input.txt");    ofstream ofile("output.txt");    int a, b;    while(ifile>>a>>b)//        printf("%d\

2015-05-17 15:33:26 836

原创 Remove Element的两种解法

Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length.

2015-05-12 20:51:15 3013

原创 memcmp比较两个C风格字符串

/* memcmp example */#include #include int main (){ char buffer1[] = "DWgaOtP12df0"; char buffer2[] = "DWGAOTP12DF0"; int n; n=memcmp ( buffer1, buffer2, sizeof(buffer1) ); if (n>0) p

2015-05-06 15:02:59 723

原创 power函数的非递归经典实现(时间复杂度仅仅为logn)

#includeusing namespace std;template T power(T x,Integer n){ if(n == 0) return 1; if(n == 1) return x; while((n&1) == 0) { x = x*x; n >>= 1; } T result = x

2015-05-06 11:24:17 1926

转载 深刻理解套接字

http://wenku.baidu.com/link?url=7pi7OjyMbiSXoAVsWsy5YBg1oSxKYyfymaJh2f1FySs76-Fo9rxUeRl_35KzRk_5yv_umNF5217ZqDe3swkV4YcvoQ1hDXNNKIfXBbinXyK对于网络编程,我们也言必称TCP/IP,似乎其它网络协议已经不存在了。对于TCP/IP,我们还知道TCP和UDP,前者

2015-05-05 11:19:50 397

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除