惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Cisco Blogs
爱范儿
爱范儿
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
Jina AI
Jina AI
Project Zero
Project Zero
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
Simon Willison's Weblog
Simon Willison's Weblog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tenable Blog
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
Last Week in AI
Last Week in AI
月光博客
月光博客
雷峰网
雷峰网
G
Google Developers Blog
V
V2EX
T
Tor Project blog
罗磊的独立博客
Schneier on Security
Schneier on Security
Know Your Adversary
Know Your Adversary
W
WeLiveSecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
P
Privacy International News Feed
S
Securelist
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
小众软件
小众软件
Scott Helme
Scott Helme
I
Intezer
T
Threat Research - Cisco Blogs
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
C
CERT Recently Published Vulnerability Notes
Security Archives - TechRepublic
Security Archives - TechRepublic
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LINUX DO - 最新话题
N
News | PayPal Newsroom
L
Lohrmann on Cybersecurity
T
Troy Hunt's Blog
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
Latest news
Latest news
AWS News Blog
AWS News Blog
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - Love Fendi

性能优化系列---查询高cup的sql State模式学习 8.17--8.24积累 sql server 2005 analysis service step by step(三):创建父子维度 sql server 2005 analysis service step by step(二):创建时间维度 sql serve 2005 analysis service step by step(一):创建标准维度 算法练习四:求N!不溢出 算法练习三:奇偶分割 算法练习二:二分查找 数据库锁 算法练习一:最大公约数与最小公倍数 索引优化 生成验证码,同时异步获取加密后的验证码 自定义控件中与脚本资源集成的若干处理方式 一条语句删除表中某字段重复的数据 动态按需异步加载js文件 在Nhibernate中使用Json.net中出现Self referencing loop的错误的处理 JQuery学习笔记 c#委托事件 入门
算法练习五:求数组中第k大的数
Love Fendi · 2009-04-08 · via 博客园 - Love Fendi

 static int FindK(IList<int> a, int k)
        {
            IList<int> listTemp;
            int start=0;
            int end = a.Count-1;
            int middle = (start + end) / 2;
            //int a=
            //listTemp.a
            int position = -1;
          
            int count = 1;
            while (position != k)
            {
                if (position < k&& position!=-1)
                {
                    k = k - position-1;
                    //if (count % 2 == 0)
                    //{
                    //    k--;
                    //}
                    //count++;
                   
                   
                }
                listTemp = new List<int>();
                listTemp.Add(a[middle]);
                position = 0;
                for (int i = start; i <= end; i++)
                {
                    if (i != middle)
                    {
                        if (a[i] <= a[middle])
                        {
                            listTemp.Insert(position,a[i]);
                            position++;
                        }
                        else
                        {
                            listTemp.Add(a[i]);
                        }
                    }
                }
              

                a = listTemp;
                if (listTemp.Count == 1)
                    return a[position];
                if (position < k)
                {
                    //if (position + 1 == k)
                    //{
                    //    return a[position];
                    //}
                    start = position +1;
                    //a = listTemp;
                    end = listTemp.Count-1;
                    middle = (start + end) / 2;
                }
                if (position >k)
                {
                    start = 0;
                    end = position-1 ;
                   
                    middle = (start + end) / 2;

                }
            }

            return a[position];
        }