using System;
using System.Collections.Generic;
namespace MyCompiler {
class Program {
public static void Main(string[] args) {
Console.WriteLine("Hello world!");
// Stack used to save the array index of each item
int[] temperatures = {73,74,75,71,69,72,76,73};
var stack = new Stack<int>();
var result = new int[temperatures.Length];
Console.WriteLine("Stack Count {0}",stack.Count);
// Go through items in the array
for (int currentIndex = 0; currentIndex < temperatures.Length; ++currentIndex) {
Console.WriteLine("Count Value ! {0}",currentIndex);
// Compare the item at the top of the stack to the current array item.
// If the item at the top of stack is less than current array item,
// save the distance between the array indexes in the result array.
while (stack.Count > 0 && temperatures[stack.Peek()] < temperatures[currentIndex]) {
Console.WriteLine("Stack Peek {0}",stack.Peek());
//Console.WriteLine("Stack Pop {0}",stack.Pop());//prints the index of the element location
// Get the distance between the two array indexes
var previousIndex = stack.Pop();
result[previousIndex] = currentIndex - previousIndex;
}
// Save the array index for this item to the stack
stack.Push(currentIndex);
}
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: