数据结构
文章平均质量分 72
小屁孩2013
这个作者很懒,什么都没留下…
展开
-
排序算法大集合
1.简单选择排序//简单选择排序void simpleSelectSort(int x[], int length) { //当前最小元素所在数组中的下标 int minItemPosition = 0; for (int i = 0; i < length; ++i) { minItemPosition = i; for (int j = i + 1; j < length; +原创 2014-04-02 22:15:03 · 591 阅读 · 0 评论 -
[LeetCode] Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note : You may assume that A has enough space (size that is greater or equal tom + n) to hold additional elements fr原创 2014-05-01 00:32:53 · 573 阅读 · 0 评论 -
[LeetCode] Remove Duplicates from Sorted List
Problem :Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. 1.C++版/*原创 2014-04-30 19:07:32 · 665 阅读 · 0 评论 -
二叉树中和为某一值的路径(剑指offer25)
题目:输入一二叉树和一个整数原创 2014-04-26 22:56:13 · 625 阅读 · 0 评论 -
重建二叉树(剑指offer6、编程之美3.9)
题目:1.给出二叉树的前序和中序遍历序列,构建出这个二叉树;2.根据二叉树原创 2014-04-27 20:28:06 · 656 阅读 · 0 评论 -
二叉树的镜像(剑指offer19)
题目:请完成一个函数,输入一个二叉树原创 2014-04-27 21:55:17 · 603 阅读 · 0 评论 -
树的子结构(剑指offer18)
题目:输入两棵二叉树A和B,判断B是不是A的子结构。二叉树的结点定义如下:原创 2014-04-27 21:30:09 · 665 阅读 · 0 评论 -
[LeetCode] Evaluate Reverse Polish Notation
Problem : Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["原创 2014-05-01 22:16:41 · 593 阅读 · 0 评论 -
[LeetCode] Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it wit原创 2014-04-29 20:46:34 · 564 阅读 · 0 评论 -
求二叉树中的叶子数
二叉树结点结构struct BinaryTreeNode { char m_chChildTag; //后序遍历时用于标识其最新一次访问的是左孩子还是右孩子 char m_chData; //用于遍历时存储结点字符 int m_nValue; //用于结点是整数数值的情况 BinaryTreeNode* m_pLeftChild; BinaryTreeNode* m_pRightCh原创 2014-04-26 21:36:31 · 1309 阅读 · 0 评论 -
找到和为sum的两个数(剑指offer41、编程之美2.12)
1.蛮力法——时间复杂度为O(n)原创 2014-04-06 23:39:14 · 889 阅读 · 1 评论 -
第一个只出现一次的字符(剑指offer35)
题目:在字符串中找出第一个只出现一次的字符。如输入“aaabbc”原创 2014-04-28 11:23:05 · 758 阅读 · 1 评论 -
二叉树遍历算法总结(剑指offer23、编程之美3.10)
1.二叉树结点的数据结构struct BinaryTreeNode { char m_chChildTag; //后序遍历时用于标识其最新一次访问的是左孩子还是右孩子 char m_chData; //用于遍历时存储结点字符 int m_nValue; //用于结点是整数数值的情况 BinaryTreeNode* m_pLeftChild; BinaryTreeNode* m_pRigh原创 2014-04-03 10:37:06 · 652 阅读 · 0 评论 -
[LeetCode] Linked List Cycle
Problem : Given a linked list, determine if it has a cycle in it.Follow up : Can you solve it without using extra space?原创 2014-04-30 19:48:15 · 494 阅读 · 0 评论 -
[LeetCode] Same Tree
Problem :Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.原创 2014-04-30 14:12:00 · 498 阅读 · 0 评论 -
查找算法大集合
1.顺序查找int sequnceSearch(const int* array, const int length, const int findValue) { if (NULL == array || 0 >= length) { return -1; } for (int i = 0; i < length; ++i) { if (findValue == array[原创 2014-04-02 20:31:01 · 571 阅读 · 0 评论 -
连续子数组的最大和(剑指offer31)
问题:输入一个整型数组,数组里有正数也有负数。原创 2014-04-07 19:52:15 · 696 阅读 · 1 评论 -
最大值与最小值(编程之美2.10)
1.求一个数组序列中元素的最小值2.求一个数组序列中原创 2014-04-05 09:44:09 · 714 阅读 · 0 评论 -
【数据结构】图的遍历之DFS和BFS
1.图的遍历包括深度优先遍历DFS和广度优先遍历BFS,这两种遍历算法在原创 2014-05-11 17:13:25 · 2333 阅读 · 0 评论 -
求二叉树的深度及判断一个二叉树是否是二叉平衡树(剑指offer39)
1.二叉树结点的数据结构struct BinaryTreeNode { int m_nValue; BinaryTreeNode* m_pLeftChild; BinaryTreeNode* m_pRightChild;};2.二叉树的深度(递归式)int binaryTreeDepth(BinaryTreeNode* rootNode) { if (NULL == ro原创 2014-04-03 22:14:09 · 661 阅读 · 0 评论 -
翻转字符串(剑指offer42)
1.输入一个英文单词的顺序,翻转单词的顺序.例如输入的单词是"student",原创 2014-04-09 21:12:28 · 722 阅读 · 0 评论 -
单链表中的常见算法问题(剑指offer5/13/15/16/17)
1.单链表的结点struct ListNode { int m_nKey; ListNode* m_pNext;};2.创建链表原创 2014-04-12 23:39:31 · 637 阅读 · 0 评论 -
最长递增子序列(编程之美2.16)
问题:给定一个序列 An =a1,a2, ... , an,找出最长的子序列使得对所有i j,ai <aj。原创 2014-04-13 00:21:57 · 702 阅读 · 0 评论 -
寻找最小(或最大)的k个数(剑指offer30)
1.利用简单排序找到前k数原创 2014-04-05 22:09:50 · 643 阅读 · 0 评论 -
最大公约数和最小公倍数(编程之美2.7)
1.最大公约数(递归式)2.最大公约数(循环)原创 2014-04-04 11:08:40 · 724 阅读 · 0 评论 -
洗牌算法
1.常见的洗牌算法void shuffle_normal(int* array, const int length) { if (NULL == array || 0 >= length) { return; } int index1 = 0, index2 = 0; for (int i = 0; i < length; ++i) { index1 = rand()原创 2014-04-25 15:45:41 · 546 阅读 · 0 评论 -
【算法】单源最短路径
1.概述正在整理中。。。。。。原创 2014-08-31 22:31:37 · 412 阅读 · 0 评论