本文整理汇总了C++中Stack::Dequeue方法的典型用法代码示例。如果您正苦于以下问题:C++ Stack::Dequeue方法的具体用法?C++ Stack::Dequeue怎么用?C++ Stack::Dequeue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack::Dequeue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GFG_LongestSubstringParen
static int GFG_LongestSubstringParen( char* string, int length )
{
Stack<int> subStringIndices;
int result = 0;
subStringIndices.Enqueue(-1);
for(int i = 0; i < length; i++)
{
if( string[i] == '(' )
{
subStringIndices.Enqueue(i);
}
else if( string[i] == ')' )
{
delete subStringIndices.Dequeue();
if( !subStringIndices.IsEmpty() )
{
int newLength = i - subStringIndices.Peek()->data;
if( result < newLength) result = newLength;
}
else
{
subStringIndices.Enqueue(i);
}
}
}
return result;
}
示例2: GFG_IsBST_GivenPreOrderTraversal
static bool GFG_IsBST_GivenPreOrderTraversal( int* array, int n )
{
Stack<int> parents;
int prevMin;
bool prevMinInitialised = false;
//Continue pushing parents onto the stack until we discover a right subtree
//If a right subtree is discovered, pop all the left nodes off the stack onto the array until the stack is empty or we find a parent of the right subtree
for(int i = 0; i < n; i++)
{
if( parents.IsEmpty() || parents.Peek()->data > array[i] )
{
parents.Enqueue(array[i]);
}
else //right subtree discovered
{
while( !parents.IsEmpty() && parents.Peek()->data < array[i] )
{
int Value = parents.Dequeue()->data;
//Test to see that the resulting array is sorted
if( prevMinInitialised && prevMin > Value )
{
return false;
}
prevMinInitialised = true;
prevMin = Value;
}
parents.Enqueue(array[i]);
}
}
//Put all of the remaining parents into our array
while( !parents.IsEmpty() ) {
int Value = parents.Dequeue()->data;
//Test to see that the resulting array is sorted
if( prevMinInitialised && prevMin > Value )
{
return false;
}
prevMinInitialised = true;
prevMin = Value;
}
return true;
}