Skip to content

Commit 2b8b65a

Browse files
authored
Merge pull request TheAlgorithms#143 from rajnishyadav321/patch-1
Added Next Greater Element
2 parents bb76af3 + 46b82fa commit 2b8b65a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

data_structures/Stacks/next.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Function to print element and NGE pair for all elements of list
2+
def printNGE(arr):
3+
4+
for i in range(0, len(arr), 1):
5+
6+
next = -1
7+
for j in range(i+1, len(arr), 1):
8+
if arr[i] < arr[j]:
9+
next = arr[j]
10+
break
11+
12+
print(str(arr[i]) + " -- " + str(next))
13+
14+
# Driver program to test above function
15+
arr = [11,13,21,3]
16+
printNGE(arr)

0 commit comments

Comments
 (0)