From the course: C# Algorithms
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Stack algorithms: Theorizing an algorithm - C# Tutorial
From the course: C# Algorithms
Stack algorithms: Theorizing an algorithm
- [Instructor] As a software engineer, you'll need to know how to leverage the built-in stack functionality when working with algorithms that keep track of state. In this lesson, we'll look at how to use the stack data structure to solve software problems. Let's say we want to print the next greater element for every element in the array. The next greater element for a given element is the first greater element on the right side of the array. If no greater elements exist, then the next greater element is a sentinel value, negative one. For example, if we were given an array with 5, 6, 3, and 50, the next greater element for 5 would be 6. The next greater element for 6 would be 50 and the same for 3. 50 does not have a next greater element to the right, so its value would be negative one. In another example, let's say we have 15, 8, 4, and 10. 15 does not have a next greater element, so it would be negative one. Eight's next greater element to the right is 10 and the same for 4. 15 is…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
What is a queue?2m
-
(Locked)
Standard queue operations in C#4m 24s
-
(Locked)
Queue algorithms: Generate binary numbers5m 21s
-
(Locked)
What is a stack?1m 56s
-
(Locked)
Basic stack operations in C#4m 23s
-
(Locked)
Stack algorithms: Theorizing an algorithm5m 5s
-
(Locked)
Stack algorithms: Implementing next greater element4m 41s
-
(Locked)
Stack algorithms: Matching parentheses6m 1s
-
(Locked)
Solution: evaluate reverse polish notation4m 27s
-
-
-
-