Total fake just he wrote the a[1] at print statement in which the the 12 is there at index 1 so, it's printed. It's not the procedure infact he just printed the direct value.
@sayamvashisht1897
Жыл бұрын
He sorted the array using selection sort and then then printed a[1] because the second largest element will be in the second position, so the code is perfectly fine.
@timepassforyou
Жыл бұрын
@@sayamvashisht1897 Then what if he don't write all this code and just print the last line. Did he get the same output or not.
@sayamvashisht1897
Жыл бұрын
@@timepassforyou that's just a coincidence that the second largest element was already placed in the second position, after using the code , you can print any nth largest element. That is the necessity of the code
@divbytes
10 ай бұрын
he is using bubble sort alogothm to find element and then swapping them after then printing 2nd largest element of sorted array
@naseeraj502
Жыл бұрын
What if the largest element occured two times?
@cherukucreation
10 ай бұрын
Your code useless when array doesn't contain unique numbers Remove duplicates by hashset and use sort method and return the second it will works
Пікірлер: 12