自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(36)
  • 收藏
  • 关注

原创 LeetCode(3)

Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters

2016-09-30 14:14:29 321

原创 LeetCode(2)

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link

2016-09-29 15:18:05 307

原创 LeetCode(1)

Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given nums

2016-09-28 17:03:10 270

原创 面试题——不用循环计算1+2+...+100之和

前几天看到校招的面试题,要求不要用循环计算出1+2+3...+100之和。当我看到这道题的时候第一反应就是用递归写,能用循环的程序不一定能用递归去写,但是能用递归的程序一定可以用循环写出。所以递归和循环是相铺相成的。       这里我也不知道递归是不是面试考官想要的最优写法,但是这题至少没用循环。这里我写完后修改了下代码,不仅仅是只计算1+2+3...+100的程序,输入一个最小的数字(如5

2016-09-28 14:51:35 2066

原创 遍历二叉树——非递归遍历

“test.cpp”#includeusing namespace std;#include#includetemplatestruct BinaryTreeNode{ T _data; BinaryTreeNode* _left; BinaryTreeNode* _right; BinaryTreeNode(const T& data = T()) :_data(

2016-09-28 14:14:48 547

原创 遍历二叉树——递归遍历

“test.cpp”#includeusing namespace std;templatestruct BinaryTreeNode{ T _data; BinaryTreeNode* _left; BinaryTreeNode* _right; BinaryTreeNode(const T& data = T()) :_data(data) ,_left(NUL

2016-09-26 23:03:07 953

原创 广义表——递归入门

“test.cpp”#includeusing namespace std;#includeenum Type{ HEAD, SUB, VALUE,};struct GeneralizedListNode{ Type _type; GeneralizedListNode* _next; //union //{ char _value; Generaliz

2016-09-25 00:05:42 775

原创 稀疏矩阵的(普通/快速)转置

“test.cpp”#includeusing namespace std;#includetemplatestruct Triple{ size_t _row; size_t _col; T _value; Triple(size_t row = 0,size_t col = 0,const T& value = T()) :_row(row) ,_col(co

2016-09-24 15:21:39 764

原创 指针和数组——面试基础(1)

刚开始学习编程的时候总以为数组就是指针,指针就是数组,容易混淆。其实,数组和指针是有区别的。数组与指针的区别:数组:1、数组要么在静态存储区被创建(全局数组),要么在栈上被创建(局部数组)2、数组名对应着(不是指向)一块内存(大小已知),其地址与容量在生命周期内保持不变,只有数组内容      可以改变。指针:1、指针可以随时指向任意类型的内存块(不同类型可以通过强制类

2016-09-23 13:48:54 422

原创 贪吃蛇——C++经典小游戏

贪吃蛇的游戏规则:上下左右方向键控制贪吃蛇游动,不要撞到墙、不要碰到自己身体,每次吃到食物速度都会加快。

2016-09-22 23:31:59 3309 1

原创 进程——pid_fork

process ID。如果说程序是静态的话,那么进程就是活动的。进程是程序在某个数据集上运行的过程,而PID就是活动进程的标识。也就说只有程序运行了,才产生进程。当然在进程中还包含线程,我们程序中的main函数就是主线程,一般程序中如果没有再定义其他线程的话,那就是单线程的。    PID就是各进程的身份标识,程序一运行系统就会自动分配给进程一个独一无二的PID。进程中止后PID被系统回收

2016-09-21 16:23:15 517

原创 顺序表——迭代器

"test.cpp"#includeusing namespace std;templateclass Vector{public: typedef T* Iterator; typedef const T* ConstIterator; Vector() :_start(NULL) ,_finish(NULL) ,_endofstorage(NULL) {}

2016-09-21 14:24:23 341

原创 稀疏矩阵的压缩存储

“test.cpp”#includeusing namespace std;#includetemplatestruct Triple{ size_t _row; size_t _col; T _value; Triple(size_t row = 0,size_t col = 0,const T& value = T()) :_row(row) ,_col(co

2016-09-20 12:09:06 415

原创 对称矩阵的压缩存储

“test.cpp”#includeusing namespace std;templateclass SymmetricMatrix{public: SymmetricMatrix(T* a,size_t n) :_n(n) ,_size(n*(n+1)/2) ,_matrix(new T[n*(n+1)/2]) { size_t index = 0; f

2016-09-20 11:26:52 859

原创 进度条——fflush(stdout)理解使用

运行结果展示“test.c”#include#includevoid proc(){ int i = 0; char proc_buf[102]; const char* latle = "|/-\\"; memset(proc_buf,'\0',sizeof(proc_buf)); while(i <= 100) { printf("[%-100s][

2016-09-19 14:23:13 2813

原创 一个数组实现两个栈——栈和队列面试题(5)

题目要求:一个数组实现两个栈"test.cpp"#includeusing namespace std;#includetemplateclass ArrayTwoStack{public: ArrayTwoStack() :_capacity(2) ,_top1(-1) ,_top2(_capacity) ,_size1(0) ,_size2(

2016-09-19 00:23:05 579

原创 元素出入栈的合法性——栈和队列面试题(4)

题目要求:元素的出,入栈顺序的合法性。如入栈{1,2,3,4,5,},出栈{4,5,3,2,1}"test.cpp"#includeusing namespace std;#include#includebool IsLegalOrder(int* arr1,int size1,int* arr2,int size2){ assert(arr1); assert(a

2016-09-18 22:53:10 399

原创 两个队列实现一个栈——栈和队列面试题(3)

题目要求:用两个队列实现一个栈,实现栈的内部函数“test.cpp”#includeusing namespace std;#includetemplateclass TwoQueueFromStack{public: TwoQueueFromStack(){} void Push(const T& data) { if(FirstQueue.empty(

2016-09-18 19:13:07 325

原创 两个栈实现一个队列——栈和队列面试题(2)

题目要求:规定用两个栈实现一个队列,实现内部函数"test.cpp"#includeusing namespace std;#includetemplateclass TwoStackFromQueue{public: TwoStackFromQueue(){} void Push(const T& data) { if(PushStack.empty()

2016-09-18 18:20:02 298

原创 最小栈——栈和队列面试题(1)

题目要求:实现一个栈,要求实现Push(出栈),Pop(入栈),Min(返回最小值操作)的时间复杂度是O(1)“test.cpp”#includeusing namespace std;#include#includetemplateclass Stack{public: Stack(){} void Push(const T& data) { if(M

2016-09-18 17:15:44 487

原创 双向循环链表——STL迭代器

“test.cpp”#define _CRT_SECURE_NO_WARNINGS 1#includeusing namespace std;templatestruct ListNode{ ListNode* _prev; ListNode* _next; T _data; ListNode(const T& data) :_prev(NULL) ,_next(

2016-09-14 13:06:56 592

原创 排序(6)——快速排序及其优化

“test.cpp”#includeusing namespace std;int MidNode(int* arr,int left,int right){ int tmp = arr[left]; while(left < right) { while(left = tmp) { right--; } swap(arr[left],arr[right]

2016-09-13 18:48:28 300

原创 迷宫问题的最短路径

“test.cpp”#define _CRT_SECURE_NO_WARNINGS 1#include using namespace std;#include #define ROW 12#define COL 10struct Pos{ int _row; int _col;};void PrintMaze(int* maze,int row,int col){

2016-09-11 21:06:19 686

原创 后缀表达式计算——栈的应用

“test.cpp”#includeusing namespace std;#include#includeenum OP{ OP_NUM, OP_SYMBOL, ADD, SUB, MUL, DIV,};struct Cell{ int _symbol; int _value;};void test(){ //12 3 4 + * 6 - 8 2 /

2016-09-11 17:52:35 380

原创 迷宫问题——栈的应用

“Maze.txt”1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 10 0 0 1 1 1 1 1 1 11 1 0 1 1 1 1 1 1 11 1 0 0 0 1 1 1 1 11 1 1 1 0 0 0 0 1 11 1 1 1 0 1 1 0 1 11 1 1 0 0 1 1 0 0 11 1 1 0 1 1 1 1 1 1

2016-09-11 16:45:29 371

原创 排序(5)——堆排序

“test.cpp”#define _CRT_SECURE_NO_WARNINGS 1#includeusing namespace std;#includevoid HeapAdjust(int* arr,int parent,size_t size){ assert(arr); int child = 2*parent+1; while(child && child <

2016-09-10 13:44:10 263

原创 排序(4)——希尔排序

“test.cpp”#define _CRT_SECURE_NO_WARNINGS 1#includeusing namespace std;#includevoid ShellSort(int* arr,size_t size){ assert(arr); int tmp = 0,i = 0,j = 0,count = size; do { count = coun

2016-09-09 22:14:17 235

原创 排序(3)——插入排序

“test.cpp”#define _CRT_SECURE_NO_WARNINGS 1#includeusing namespace std;#includevoid InsertSort(int* arr,size_t size){ assert(arr); int i = 1; while(i < size) { int j = 0; int tmp = ar

2016-09-09 22:12:54 217

原创 排序(2)——选择排序及其优化

“test.cpp”#define _CRT_SECURE_NO_WARNINGS 1#includeusing namespace std;#includevoid SelectSort_OP(int* arr,size_t size){ assert(arr); int min = 0; int max = 0; for(int i = 0;i < size;i++)

2016-09-09 20:07:29 296

原创 队列——链式存储

“test.cpp”#define _CRT_SECURE_NO_WARNINGS 1#includeusing namespace std;#includetemplatestruct QueueNode{ T _data; QueueNode* _next; QueueNode(const T& data) :_data(data) ,_next(NULL)

2016-09-09 14:19:24 288

原创 栈——顺序存储

“test.cpp”#define _CRT_SECURE_NO_WARNINGS 1#includeusing namespace std;#includetemplateclass Stack{public: Stack() :_arr(NULL) ,_size(0) ,_capacity(0) {} void Push(const T& data)

2016-09-09 14:18:13 284

原创 排序(1)——冒泡排序及其优化

“test.cpp”#define _CRT_SECURE_NO_WARNINGS 1#includeusing namespace std;//优化趟数里的次数void BubbleSort_OP2(int* arr ,size_t size){ int n = 0; int m = size-1; bool flag = true; for(int i = 0;i <

2016-09-09 14:15:46 330

原创 图——邻接表

邻接表:邻接表是图的一种链式存储结构。对图的每个顶点建立一个单链表(n个顶点建立n个单链表),第i个单链表中的结点包含顶点Vi的所有邻接顶点。又称链接表。“test.cpp”#define _CRT_SECURE_NO_WARNINGS 1#includeusing namespace std;#include "GraphLink.h"void Test(){ Gr

2016-09-07 13:06:51 288

原创 图——邻接矩阵

邻接矩阵:用一个一维数组存放图中所有顶点数据;用一个二维数组存放顶点间关系(边或弧)的数据,这个二维数组称为邻接矩阵。用邻接矩阵表示图,很容易确定图中任意两个顶点是否有边相连。邻接矩阵分为有向图邻接矩阵和无向图邻接矩阵。对无向图(无向简单图)而言,邻接矩阵一定是对称的,而且对角线一定为零,有向图则不一定如此。“test.cpp”#define _CRT_SECURE_NO_WARN

2016-09-06 21:54:38 5309

原创 二分查找——递归与非递归

二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好;其缺点是要求待查表为有序表,且插入删除困难。因此,折半查找方法适用于不经常变动而查找频繁的有序列表。首先,假设表中元素是按升序排列,将表中间位置记录的关键字与查找关键字比较,如果两者相等,则查找成功,返回当前位置下标;否则利用中间位置记录将表分成前、后两个子表,如果中间位置记录的关键字大于查找关键字,则进一步查找前一子表,否则进一步查

2016-09-06 11:46:17 803

原创 剑指offer——斐波那契数列多种方法实现

斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368。         这个数列从第2项开始,每一项都等于前两项之和。"test.cpp"#define _CRT_S

2016-09-05 22:46:54 461

空空如也

空空如也

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

TA关注的人

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