Skip to content

Commit

Permalink
Merge pull request TheAlgorithms#143 from rajnishyadav321/patch-1
Browse files Browse the repository at this point in the history
Added Next Greater Element
  • Loading branch information
harshildarji authored Oct 18, 2017
2 parents bb76af3 + 46b82fa commit 2b8b65a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions data_structures/Stacks/next.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2b8b65a

Please sign in to comment.