本文整理汇总了C++中TStack::push方法的典型用法代码示例。如果您正苦于以下问题:C++ TStack::push方法的具体用法?C++ TStack::push怎么用?C++ TStack::push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TStack
的用法示例。
在下文中一共展示了TStack::push方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv) {
TStack stack;
stack.push(Triangle(1, 1, 1));
stack.push(Triangle(2, 2, 2));
stack.push(Triangle(3, 3, 3));
std::cout << stack;
Triangle t, tmp1, tmp2;
t = stack.pop(); std::cout << t;
t = stack.pop(); std::cout << t;
t = stack.pop(); std::cout << t;
t = Triangle(15, 15, 15);
tmp1 = Triangle(20, 15, 15);
isEqual(t, tmp1);
tmp1 = t;
isEqual(t, tmp1);
return 0;
}
示例2: main
int main() {
srand(time(NULL)); // Seed random number generator
TStack<Trash> bin; // Default to ownership
// Fill up the Trash bin:
for (int i = 0; i < 30; i++) {
switch (rand() % 3) {
case 0:
bin.push(new Aluminum(rand() % 100));
break;
case 1:
bin.push(new Paper(rand() % 100));
break;
case 2:
bin.push(new Glass(rand() % 100));
break;
}
// Bins to sort into:
TStack<Trash> glassBin(0); // No ownership
TStack<Trash> paperBin(0);
TStack<Trash> alBin(0);
TStackIterator<Trash> sorter(bin);
// Sort the Trash:
// (RTTI offers a nicer solution)
while (sorter) {
// Smart pointer call:
switch(sorter->trashType()) {
case AluminumT:
alBin.push(sorter.current());
break;
case PaperT:
paperBin.push(sorter.current());
break;
case GlassT:
glassBin.push(sorter.current());
break;
}
sorter++;
}
SumValue(alBin, out);
SumValue(paperBin, out);
SumValue(glassBin, out);
SumValue(bin, out);
return 0;
}
} ///:~
示例3: sqrt
//вычисление корня
void sqrt()
{
if(!Data.isempty())
{
double x = Data.pop();
Data.push(std::sqrt(x));
it++;
}
else error("cann't execute sqrt, stack is empty");
}
示例4: mul
//умножение
void mul()
{
if(Data.size()>1)
{
double x = Data.pop();
double y = Data.pop();
Data.push(x*y);
it++;
}
else error("cann't execute mul, stack is empty");
}
示例5: sub
//разность
void sub()
{
if(Data.size()>1)
{
double y = Data.pop();
double x = Data.pop();
Data.push(x-y);
it++;
}
else error("cann't execute add, stack is empty");
}
示例6: start
//запуск виртуальной машины
void start()
{
if(Code == nullptr) {
error("Not found code");
return;
}
while(1)
{
char cur = Code[it];
int curit = it;
switch (Code[it]) {
//в зависимости от кода функции выбираем действие
case CNVAR:
it++;
getname();
add_var(string(NameVar));
break;
case CSVAR:
it++;
getname();
set_var(NameVar, Data.pop());
break;
case CPUSH:
it++;
Data.push(*((double*)(Code+it)));
it+=sizeof(double);
break;
case CMULT:
mul();
break;
case CADD:
add();
break;
case CSUB:
sub();
break;
case CDIV:
div();
break;
case CSQRT:
sqrt();
break;
case COUT:
print();
break;
case CHALT:
return;
default:
error("Cann't understand command.");
break;
}
}
}
示例7: div
//деление
void div()
{
if(Data.size()>1)
{
double y = Data.pop();
double x = Data.pop();
if(y) Data.push(x/y);
else error("devide by zero");
it++;
}
else error("cann't execute add, stack is empty");
}