数据结构与算法
fxqcn
这个作者很懒,什么都没留下…
展开
-
二分查找
using System; using System.Collections.Generic; namespace 二分查找 { class Program { static void Main(string[] args) {原创 2011-10-12 11:52:27 · 410 阅读 · 0 评论 -
C# 双向链表
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace csharp链表 { class Program { public class Node { private Node child;原创 2011-11-01 09:39:10 · 692 阅读 · 0 评论 -
用代码验证阿里巴巴的一道关于男女比例的面试题
今天在CSDN首页看了一篇博客《阿里巴巴的面试》。 其中有一个问题,比较有意思: 说澳大利亚的父母喜欢女孩,如果生出来的第一个女孩,就不再生了,如果是男孩就继续生,直到生到第一个女孩为止,问若干年后,男女的比例是多少? 刚看到问题是的思维逻辑:用递推法,假设一对夫妻,生了个女儿,就不再要了;另外一对夫妻,生了个儿子,再要一个,是女儿,然后也就不要了。第一感觉,应该是女的比男的多。然后思考如何转载 2011-11-02 14:10:19 · 796 阅读 · 0 评论 -
STL hashtable 源码分析
在stl_hash_fun.h中,定义如下 inline size_t __stl_hash_string(const char* __s) { unsigned long __h = 0; for ( ; *__s; ++__s) __h = 5*__h + *__s; return size_t(__h); } __STL_TEMPLATE_NULL struct h原创 2014-07-30 23:05:28 · 918 阅读 · 0 评论 -
hash_map 和 hash_mutilmap
class hash_map { private: typedef hashtable,_Key,_HashFcn, _Select1st >,_EqualKey,_Alloc> _Ht; _Ht _M_ht; //可见hashmap内部的是使用hashtable实现的 public: typedef typename _Ht::key_typ原创 2014-07-30 23:29:58 · 1172 阅读 · 0 评论 -
leetcode 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exa原创 2014-08-10 13:10:58 · 481 阅读 · 0 评论 -
leetcode 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,原创 2014-08-10 13:02:54 · 541 阅读 · 0 评论 -
leetcode Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, w原创 2014-08-10 13:07:12 · 517 阅读 · 0 评论 -
leetcode 4sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Eleme原创 2014-08-10 13:13:23 · 653 阅读 · 0 评论 -
求1+2+…+n,要求不能使用乘除法、for、while、if、else...
题目:求1+2+…+n, 要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)。 其实会有很多种解法,但是下面给出了一个简单的代码-----巧用递归算法。 view plainprint? #include #include #include int add_转载 2011-10-31 11:49:34 · 705 阅读 · 0 评论 -
堆栈的实现
#include #include #include #define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 #define OK 1 #define ERROR 0 #define OVERFLOW -2 typedef int status; typedef struct{ int *base; int *top; int stac转载 2011-10-20 14:37:46 · 462 阅读 · 0 评论 -
顺序线性表
#include #define OK 1 #define ERROR -1 #define MAX_SIZE 100 typedef int Status ; typedef int ElemType ; typedef struct {原创 2011-10-02 20:59:47 · 498 阅读 · 0 评论 -
字符串比较算法
using System; namespace 字符串比较算法 { class Program { static void Main(string[] args) { string s1 = "abcdaf原创 2011-09-30 17:10:14 · 700 阅读 · 0 评论 -
二叉树
#include #include typedef struct Node { char data; struct Node *lchild; struct Node *rchild; }BiTreeNode; BiTreeNode *CreatBiTree(BiTreeN转载 2011-10-13 21:40:13 · 412 阅读 · 0 评论 -
BF算法与KMP算法
using System; namespace kmp { /// /// Summary description for Class1. /// class Class1 { /// /// The转载 2011-10-14 15:25:25 · 664 阅读 · 0 评论 -
汉诺塔算法
using System; namespace 汉诺塔算法 { class Program { static void Main(string[] args) { Console.WriteLine("盘数原创 2011-10-14 15:59:02 · 1436 阅读 · 0 评论 -
算法:用数组求两个字符串最长的公共子串
using System; using System.Collections; namespace 数据结构_数组 { class Program { public static Int32 MaxLen; public stat原创 2011-10-15 11:13:07 · 1745 阅读 · 0 评论 -
单线性链表
#include #include typedef struct LNode { int StudentNo; int Math; struct LNode *next; }LNode; LNode *inint(void); void display(LNode *L); int GetLength(LNode *L); LNode *AddItm(LNode *L,int num,in原创 2011-10-19 23:16:23 · 687 阅读 · 0 评论 -
leetcode Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).原创 2014-08-10 13:08:46 · 576 阅读 · 0 评论