+ 1

Single dimensional array

#How can i get second largest and second smallest number in any array? I want logic with different different methods?

17th Dec 2018, 4:20 AM
Umesh Sharma
Umesh Sharma - avatar
5 Answers
+ 21
Hy Umesh Sharma ● simple way to solve this is to sort array in ascending order & then taking out values at index n-2 & 1. ● U can click on profile pic of user to get to his SL profile
17th Dec 2018, 4:38 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 2
thank you gaurav. but with sorting i knw but i want without sorting concept.. thats why i am here actully.... i done with sorting but without sorring i want. thanks buddy again👍
17th Dec 2018, 4:47 AM
Umesh Sharma
Umesh Sharma - avatar
0
You should first get the largest and the smallest numbers in the array, then go through the array and check every number that is greater then previous number and smaller then largest number. For the second smalles do same thing but check for every number that is smaller then previous and greater then smallest number! for example: int arr[6] = {1, 2, 3, 4, 5, 6}; int secondMax = 0; int secondMin = 0; for(int i = 0; i < 6; i++) { if( arr[i] > secondMax && i < 6) secondMax = arr[i]; } for(int i = 0; i < 6; i++) { if(arr[i] < secondMin && i > 1) secondMin = arr[i]; }
17th Dec 2018, 4:28 AM
Sekiro
Sekiro - avatar
0
thank you sekiro....thank you so much.....
17th Dec 2018, 4:33 AM
Umesh Sharma
Umesh Sharma - avatar
0
by the way, where you from? what you do? from which country?
17th Dec 2018, 4:34 AM
Umesh Sharma
Umesh Sharma - avatar