数组中的第二大元素 [英] second largest element in an array

查看:75
本文介绍了数组中的第二大元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


任何人都可以帮我编写一个C程序来查找数组中第二大的

元素。
<不使用任何排序算法的
。阵列可能会重复元素。

算法应该在O(n)时间运行。


Rajesh

Hello Everybody,

Can anybody help me to write a C program for finding the second largest
element in an array.

without using any sort algo. The array may conatin duplicate elements.
The algo should run in O(n) time.

Rajesh

推荐答案

Rajesh写道:
任何人都可以帮我编写一个C程序,用于在不使用任何数组的情况下查找数组中的第二个最大元素算法。
数组可能包含重复元素。算法应该在O(n)
时间运行。
Can anybody help me to write a C program for finding the second
largest element in an array without using any sort algo. The
array may contain duplicate elements. The algo should run in O(n)
time.




再次向我们展示你到目前为止所做的事情。



Again, show us what you''ve come up with so far.


请定义数组中的第二大元素。

对于以下第二大元素数组?


a)int x [] = {1};

b)int x [] = {2,2};

c)int x [] = {4 ,4,8,8};


b)的答案是x [0]或x [1]?

Please define "second largest element in an array".
For the following arrays which is the second largest element?

a) int x[] = {1};
b) int x[] = {2, 2};
c) int x[] = {4, 4, 8, 8};

The answer to b) is x[0] or x[1]?


答案a)应该是max1 = 1和max2 = 1

答案b)应该是max1 = 2和max2 = 2

答案c )应该是max1 = 8和max2 = 4

Answer to a) should be max1=1 and max2=1
Answer to b) should be max1=2 and max2=2
Answer to c) should be max1=8 and max2=4


这篇关于数组中的第二大元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆