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

推荐订阅源

C
Cyber Attacks, Cyber Crime and Cyber Security
The Last Watchdog
The Last Watchdog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
W
WeLiveSecurity
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
News | PayPal Newsroom
D
DataBreaches.Net
博客园_首页
Y
Y Combinator Blog
F
Fortinet All Blogs
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
T
Tailwind CSS Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub Blog
B
Blog RSS Feed
C
CERT Recently Published Vulnerability Notes
P
Privacy & Cybersecurity Law Blog
Help Net Security
Help Net Security
S
SegmentFault 最新的问题
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
N
News and Events Feed by Topic
Schneier on Security
Schneier on Security
V
Vulnerabilities – Threatpost
A
About on SuperTechFans
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
L
LINUX DO - 热门话题
Simon Willison's Weblog
Simon Willison's Weblog
雷峰网
雷峰网
G
Google Developers Blog
Cyberwarzone
Cyberwarzone
I
Intezer
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
C
Check Point Blog
AI
AI
博客园 - 【当耐特】
有赞技术团队
有赞技术团队
博客园 - 司徒正美

博客园 - 超子

My Development PC - II My Development PC - I 为Migrator.net制作一个可自动生成版本号的项目模板 Hone C# III La Maison en Petits Cubes Hone C# II Hone C# 卡壳 游戏开发学习 02 游戏开发学习 01 游戏开发学习 00 语言学习开篇 - 写在前面 送同志们留念:动态指示条(Activity indicators) 送同志们留念:看看我们的MSDN China 都为我们作了些什么 热点杂记:Atlas Control Toolkits 更新 热点杂记:Asp.net 的演示视频 VS2005 中的 Template 热点杂记:Scott Guthrie 中文博客开通 送同志们留念:各种符号的英文名称
C#次大数的函数
超子 · 2007-01-12 · via 博客园 - 超子

好像昨天看了个博客,提到次大数函数。想了想写了一个备忘。

public int GetSecMax(int[] dataset)
    
{
        
if (dataset == null || dataset.Length == 1)
            
throw new Exception("空或只有一个数");          //一个无解异常

        
int Max = dataset[0];
        
int secMax;
        
bool hasMax = false;

        
for (int i = 1; i < dataset.Length; i++)
        
{
            
if (!hasMax && (Max != dataset[i]))
                hasMax 
= true;
            
if (Max < dataset[i])
                Max 
= dataset[i];
        }


        
if (hasMax)                                         //有解
        {
            secMax 
= Max;
            
bool hasSecMax = false;
            
for (int j = 0; j < dataset.Length; j++)
            
{
                
if (!hasSecMax)
                
{
                    
if (dataset[j] < Max)
                    
{
                        secMax 
= dataset[j];
                        hasSecMax 
= true;
                    }

                }

                
else
                

                    
if((secMax < dataset[j]) && (dataset[j] < Max))
                        secMax 
= dataset[j];
                }

            }


            
return secMax;
        }


        
throw new Exception("无解");  

    }

posted on 2007-01-12 10:35  超子  阅读(316)  评论(0)    收藏  举报

刷新页面返回顶部