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


C++ SList::PushFront方法代码示例

本文整理汇总了C++中SList::PushFront方法的典型用法代码示例。如果您正苦于以下问题:C++ SList::PushFront方法的具体用法?C++ SList::PushFront怎么用?C++ SList::PushFront使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SList的用法示例。


在下文中一共展示了SList::PushFront方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    SList<int> list;
    list.PushFront(4);
    list.PushBack(5);
    list.PushFront(3);
    list.PushBack(6);
    list.PushBack(7);
    list.PushBack(8);
    list.PushBack(9);
    list.PushFront(2);
    list.Insert(1, 11);
    list.Insert(3, 13);
    list.Insert(5, 15);
    list.Insert(20, 20);

    list.Print();
    list.Delete(1);
    list.Print();
    list.Delete(11);
    list.Print();
    list.Delete(7);
    list.Print();

    SList<int> list2;
    list2.PushBack(1);
    list2.Print();
    list2.Reverse();
    list2.Print();

    SList<int> list3;
    list3.PushBack(1);
    list3.PushBack(2);
    list3.Print();
    list3.Reverse();
    list3.Print();

    SList<int> list4;
    list4.PushBack(5);
    list4.PushBack(4);
    list4.PushBack(3);
    list4.PushBack(2);
    list4.PushBack(1);
    list4.Print();
    list4.Reverse();
    list4.Print();


    return 0;
}
开发者ID:Seungchul-Han,项目名称:algorithm,代码行数:50,代码来源:slist.cpp

示例2: if

	//Convert infix to postfix using shunting yard
	SList<std::string> XMLParseHelperExpression::ShuntingYard(const SList<std::string>& expressionTokens)
	{

		//Stack used with conversion algorithm
		SList<std::string> stack;

		//Stores return value
		SList<std::string> output;

		for (std::string& item : expressionTokens)
		{
			if (!mLegalOperators.ContainsKey(item))//If the item is not an operator, it must be a number and is there for immediately pushed onto the stack
			{
				output.PushBack(item);
			}
			else if(item == "(")//Check for open parentheses
			{
				stack.PushFront(item);
			}
			else if (item == ")")//Check for close parentheses
			{
				while (stack.Front() != "(")//Add operators to the output until we find the other parentheses
				{
					output.PushBack(stack.Front());
					stack.PopFront();
					if (stack.Size() == 0)//There's a problem if we couldn't find the other parentheses at all
					{
						throw std::exception("Expression formed with uneven number of parentheses");
					}
				}
				stack.PopFront();//Get rid of the open parentheses
			}
			else//Otherwise, we're a normal operator. 
			{
				if (stack.Size() == 0)//We go into the stack if its empty.
				{
					stack.PushFront(item);
				}
				else//Otherwise we have to compare precedence
				{
					//Make sure our operators are actually legal
					if (!mLegalOperators.ContainsKey(stack.Front()) || !mLegalOperators.ContainsKey(item))
					{
						throw std::exception("Unknown operator put into expression");
					}

					int stackPrecedence = mLegalOperators.Find(stack.Front())->second;
					int itemPrecedence = mLegalOperators.Find(item)->second;

					if (itemPrecedence > stackPrecedence)//If the new item has greater precedence, it is put onto the stack
					{
						stack.PushFront(item);
					}
					else//If the item has less precedence or the same precedence, we put the current operator into the output and then push this item into the stack
					{
						output.PushBack(stack.Front());
						stack.PushFront(item);
					}

				}
			}
		}
		//Push the remaining operators on the stack into the output
		while (stack.Size() > 0)
		{
			output.PushBack(stack.Front());
			stack.PopFront();
		}		

		return output;

	}
开发者ID:CalWLee,项目名称:FIEATetris,代码行数:73,代码来源:XMLParseHelperExpression.cpp


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