Hi ! everyone im a begginer c++ programmer and Im trying to make a programm that will print the next greatest element of an array. for example [4,5,2,25} if the element doesnt have a greater element next to it the next greater element should be considered as 1.
4 --> 5
5 --> 25
2 --> 25
25 --> -1
it works ok but it doesnt show the first element correctly. What am i doing worng? Any help is very much appreciated. Thanks everyone.
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
const int arr = 4;
int array [arr]= { 4, 5,2, 25 };
I would suggest sorting out array from biggest to smallest using bubble sort and then print 2nd array.
So in case you have array of 5 elements you would print array[1].
So im Given an array, and i have to print the Next Greater Element (NGE) for every element. The Next greater Element for an element x is the first greater element on the right side of x in array. Elements for which no greater element exist, consider next greater element as 1. It works but it doesnt print outt the NGE for the first element for some reason