本文整理汇总了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;
}
示例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;
}