Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

print every next closest largest element of array

Given an array of integers values. Write an efficient program (algorithm) to print every next smallest element of array. this is next node are closest rightmost element of array key.

Example

Suppose array contain following nodes. view input and accepted output.

Stack Areamainarray [0] 5 [1] 2 [2] 4 [3] 3 [4] 7 [5] 6size (int) =6

Accepted result

 5 -> 6  2 -> 3  4 -> 6  3 -> 6  7 -> -1  6 -> -1 

Explanation

Program for Find next largest rightmost of every elements of given array. Time complexity O(n^2).

Output

View process.

Stack Areamainarray [0] 5 [1] 2 [2] 4 [3] 3 [4] 7 [5] 6size (int) =6next_smallestarray(pointer)i (int) =3j (int) =6result (int) =6size (int) =6

View steps of execution

Submit your solution in comment section.

Spread the post

Recommended Posts: