
数据结构与算法
fxqcn
这个作者很懒,什么都没留下…
展开
-
二分查找
using System;using System.Collections.Generic;namespace 二分查找{ class Program { static void Main(string[] args) {原创 2011-10-12 11:52:27 · 428 阅读 · 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 · 713 阅读 · 0 评论 -
用代码验证阿里巴巴的一道关于男女比例的面试题
今天在优快云首页看了一篇博客《阿里巴巴的面试》。其中有一个问题,比较有意思:说澳大利亚的父母喜欢女孩,如果生出来的第一个女孩,就不再生了,如果是男孩就继续生,直到生到第一个女孩为止,问若干年后,男女的比例是多少?刚看到问题是的思维逻辑:用递推法,假设一对夫妻,生了个女儿,就不再要了;另外一对夫妻,生了个儿子,再要一个,是女儿,然后也就不要了。第一感觉,应该是女的比男的多。然后思考如何转载 2011-11-02 14:10:19 · 819 阅读 · 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 · 947 阅读 · 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 · 1191 阅读 · 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 · 513 阅读 · 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 · 565 阅读 · 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 · 531 阅读 · 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 · 679 阅读 · 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 · 731 阅读 · 0 评论 -
堆栈的实现
#include#include#include#define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define OK 1#define ERROR 0#define OVERFLOW -2typedef int status;typedef struct{ int *base; int *top; int stac转载 2011-10-20 14:37:46 · 478 阅读 · 0 评论 -
顺序线性表
#include#define OK 1#define ERROR -1#define MAX_SIZE 100typedef int Status ;typedef int ElemType ; typedef struct {原创 2011-10-02 20:59:47 · 518 阅读 · 0 评论 -
字符串比较算法
using System;namespace 字符串比较算法{ class Program { static void Main(string[] args) { string s1 = "abcdaf原创 2011-09-30 17:10:14 · 727 阅读 · 0 评论 -
二叉树
#include#includetypedef struct Node{ char data; struct Node *lchild; struct Node *rchild;}BiTreeNode;BiTreeNode *CreatBiTree(BiTreeN转载 2011-10-13 21:40:13 · 428 阅读 · 0 评论 -
BF算法与KMP算法
using System;namespace kmp{ /// /// Summary description for Class1. /// class Class1 { /// /// The转载 2011-10-14 15:25:25 · 681 阅读 · 0 评论 -
汉诺塔算法
using System;namespace 汉诺塔算法{ class Program { static void Main(string[] args) { Console.WriteLine("盘数原创 2011-10-14 15:59:02 · 1455 阅读 · 0 评论 -
算法:用数组求两个字符串最长的公共子串
using System;using System.Collections;namespace 数据结构_数组{ class Program { public static Int32 MaxLen; public stat原创 2011-10-15 11:13:07 · 1769 阅读 · 0 评论 -
单线性链表
#include#includetypedef 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 · 714 阅读 · 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 · 613 阅读 · 0 评论