mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27:02 +00:00
Added Next Greater Element
Element NGE 4 --> 5 5 --> 25 2 --> 25 25 --> -1
This commit is contained in:
parent
aa8485b4df
commit
46b82fa249
16
data_structures/Stacks/next.py
Normal file
16
data_structures/Stacks/next.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Function to print element and NGE pair for all elements of list
|
||||
def printNGE(arr):
|
||||
|
||||
for i in range(0, len(arr), 1):
|
||||
|
||||
next = -1
|
||||
for j in range(i+1, len(arr), 1):
|
||||
if arr[i] < arr[j]:
|
||||
next = arr[j]
|
||||
break
|
||||
|
||||
print(str(arr[i]) + " -- " + str(next))
|
||||
|
||||
# Driver program to test above function
|
||||
arr = [11,13,21,3]
|
||||
printNGE(arr)
|
Loading…
Reference in New Issue
Block a user