当前位置: 首页>>代码示例>>C++>>正文


C++ Stack::Dequeue方法代码示例

本文整理汇总了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;
}
开发者ID:degrand1,项目名称:DataStructures,代码行数:27,代码来源:GFG_Stacks.cpp

示例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;
}
开发者ID:degrand1,项目名称:DataStructures,代码行数:43,代码来源:GFG_Stacks.cpp


注:本文中的Stack::Dequeue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。