-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcode_1.cpp
44 lines (39 loc) · 938 Bytes
/
code_1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// code_1.cpp
// Algorithm
//
// Created by Mohd Shoaib Rayeen on 23/11/18.
// Copyright © 2018 Shoaib Rayeen. All rights reserved.
//
#include <iostream>
#include <vector>
using namespace std;
void printNextGreaterElement(vector<int> arr) {
int n = int(arr.size());
int next;
cout << "\nElement\t|\tNGE\n";
cout << "------------------\n";
for (int i = 0; i < n; i++) {
next = -1;
for (int j = i + 1; j < n; j++) {
if (arr[i] < arr[j]) {
next = arr[j];
break;
}
}
cout << "\t" << arr[i] << "\t|\t " << next << endl;
}
cout << endl;
}
int main() {
int n;
cout << "\nEnter Size of Array\t:\t";
cin >> n;
vector<int> array(n);
cout << "\nEnter Array Element\n";
for (int i = 0; i < n; i++ ) {
cin >> array[i];
}
printNextGreaterElement(array);
return 0;
}