One important thing to note here that in this process multiple local maximums can be discovered in a single pass and all of them must be remembered to use in later passes of the algorithm. A stack can be used to accomplish this. When a new maximum value is found, there should be an interchange between the old maximum value and the value located just before the current maximum value and this new location of the old maximum value should be pushed on the stack. When the end of the list is reached, the top item in the stack is considered to be the location of the former maximum value. Then the latest maximum value is swapped with the last item and the location of the current maximum value is considered as the starting point in the next iteration to look for the maximum. The next pass starts by assigning the value at the location stored at top in the stack to the current maximum. The local maximums stored in the stack as indices are sorted in ascending order according to their discovery time. The most recently discovered local maximum is always the largest and the initial local maximum is the smallest among them. Figure-1 illustrates the operations and the relationships among them in the proposed algorithm.