Rank of all elements in a Stream in descending order when they arrive | C ++ program to rank of all elements in a Stream in descending order when they arrive ; FindRank function to find rank ; Rank of first element is always 1 ; Iterate over array ; As element let say its rank is 1 ; Element is compared with previous elements ; If greater than previous than rank is incremented ; print rank ; Driver code ; array named arr ; length of arr
#include <iostream> NEW_LINE using namespace std ; void FindRank ( int arr [ ] , int length ) { cout << "1" << " ▁ " ; for ( int i = 1 ; i < length ; i ++ ) { int rank = 1 ; for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ j ] > arr [ i ] ) rank ++ ; } cout << rank << " ▁ " ; } } int main ( ) { int arr [ ] = { 88 , 14 , 69 , 30 , 29 , 89 } ; int len = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; FindRank ( arr , len ) ; return 0 ; }