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


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

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


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

示例1: main

int main()
{
	Stack<string> myStringStack;

	myStringStack.Push( "Hello" );
	myStringStack.Push( "Saluton" );
	myStringStack.Push( "Konnichiwa" );
	myStringStack.Push( "Bonjour" );
	myStringStack.Push( "Hola" );

	while ( myStringStack.GetSize() != 0 )
	{
		cout << myStringStack.Top() << endl;
		myStringStack.Pop();
	}

	Stack<int> myIntStack;

	myIntStack.Push( 1 );
	myIntStack.Push( 1 );
	myIntStack.Push( 2 );
	myIntStack.Push( 3 );
	myIntStack.Push( 5 );

	while ( myIntStack.GetSize() != 0 )
	{
		cout << myIntStack.Top() << endl;
		myIntStack.Pop();
	}


	return 0;
}
开发者ID:sebCarabali,项目名称:Problem-Solving-and-Programming-II,代码行数:33,代码来源:main.cpp

示例2: RandomTests

bool RandomTests()
{
	Test t("Stack Random tests");
	Stack s;
	for (int i=0; i<100000; i++)
	{
		s.Push(2*i);
		t.VerifyTrue(s.Top()==2*i,"Top element should be 2*i");
		t.VerifyTrue(s.Peek()==-1,"Peeked element should be default");
		t.VerifyTrue(s.GetSize()==1,"Size should be i+1");
		t.VerifyTrue(s.Pop()==2*i,"Popped element should be 2*i");
		t.VerifyTrue(s.Top()==-1,"Top should now be default");
	}
	t.VerifyTrue(s.GetSize()==0,"Size should be 0");
	return t.isPassed();
}
开发者ID:ShreyanGupta,项目名称:Programs,代码行数:16,代码来源:StackTest.cpp

示例3: StackPopTests

bool StackPopTests()
{
	Test t("Stack Popping tests");
	Stack s;
	for (int i=0; i<10000; i++)
	{
		s.Push(i);
	}
	for (int i=0; i<9999;i++)
	{
		t.VerifyTrue(s.Pop()==10000-1-i, "Popped value should be 10k -1 -i");
		t.VerifyTrue(s.GetSize()==10000-1-i,"Size should be 10k-1-i");
		t.VerifyTrue(s.Peek()==10000-3-i, "Peek should be 10k-3-i");
		t.VerifyTrue(s.Top()==10000-2-i,"Top should be 10k-2-i");
	}
	s.Pop();
	for (int i=0; i<100000; i++)
	{
		t.VerifyTrue(s.Pop()==-1, "Default Value should be returned");
		t.VerifyTrue(s.GetSize()==0, "Size should be 0");
	}
	return t.isPassed();
}
开发者ID:ShreyanGupta,项目名称:Programs,代码行数:23,代码来源:StackTest.cpp

示例4: StackPushTests

bool StackPushTests()
{
	Test t("Stack Pushing tests");
	Stack s;
	for (int i=0;i<10000; i++)
	{
		s.Push(i);
		t.VerifyTrue(s.Top()==i,"Top should be i");
		t.VerifyTrue(s.GetSize()==i+1,"Size should be i+1");
		t.VerifyTrue(s.Peek()==i-1,"Peeked value should be  i-1");
		t.VerifyTrue(s.IsEmpty()==false,"Stack should not be empty");
	}
	return t.isPassed();
}
开发者ID:ShreyanGupta,项目名称:Programs,代码行数:14,代码来源:StackTest.cpp

示例5: main

int main()
{
	Queue<string> myStringQueue;

	myStringQueue.Push( "Hello" );
	myStringQueue.Push( "Saluton" );
	myStringQueue.Push( "Konnichiwa" );
	myStringQueue.Push( "Bonjour" );
	myStringQueue.Push( "Hola" );

	Stack<string> myStringStack;

	myStringStack.Push( "Hello" );
	myStringStack.Push( "Saluton" );
	myStringStack.Push( "Konnichiwa" );
	myStringStack.Push( "Bonjour" );
	myStringStack.Push( "Hola" );

	int count = 0;
	while ( myStringStack.GetSize() != 0 )
	{
		cout << "Loop " << count << endl;
		cout << "\t Stack: " << myStringStack.Top() << endl;
		cout << "\t Queue: " << myStringQueue.Front() << endl;
		cout << endl;
		count++;

		myStringStack.Pop();
		myStringQueue.Pop();
	}

	cout << "Press a key to continue..." << endl;
	cin.get();

	Queue<int> myIntQueue;

	myIntQueue.Push( 1 );
	myIntQueue.Push( 1 );
	myIntQueue.Push( 2 );
	myIntQueue.Push( 3 );
	myIntQueue.Push( 5 );

	Stack<int> myIntStack;

	myIntStack.Push( 1 );
	myIntStack.Push( 1 );
	myIntStack.Push( 2 );
	myIntStack.Push( 3 );
	myIntStack.Push( 5 );

	count = 0;
	while ( myIntStack.GetSize() != 0 )
	{
		cout << "Loop " << count << endl;
		cout << "\t Stack: " << myIntStack.Top() << endl;
		cout << "\t Queue: " << myIntQueue.Front() << endl;
		cout << endl;
		count++;

		myIntStack.Pop();
		myIntQueue.Pop();
	}

	cout << "Press a key to exit..." << endl;
	cin.get();

	return 0;
}
开发者ID:sebCarabali,项目名称:Problem-Solving-and-Programming-II,代码行数:68,代码来源:main.cpp

示例6: main

int main(int argc, const char * argv[])
{

    ofstream outFile;
    outFile.open("Output.txt");


    bool done = false;
    int game = 1;

    while (done != true)
    {

        cout << "Game " << game;
        cout << endl << endl;
        Stack cards;
        int players[5];
        for (int i = 0; i < 5; i++)
        {
            players[i] = 0;
        }

        srand(time(NULL));

        for (int i = 0; i < 100; i++)
        {
            cards.Push( (rand() % 5));

        }


        while(cards.GetSize() != 0)
        {
            for (int i = 0; i < 5; i++)
            {
                players[i] += cards.Top();
                cards.Pop();
            }
        }


        int max = players[0];
        int maxPlayer;
        for (int i = 0; i < 4; i++)
        {
            if (max < players[i+1])
            {
                max = players[i+1];
                maxPlayer = i+1;
            }
        }


        cout << "Game " << game << " Score: " << endl;
        cout << "-------------" << endl;
        cout << "Player 1: " << players[0] << endl;
        cout << "Player 2: " << players[1] << endl;
        cout << "Player 3: " << players[2] << endl;
        cout << "Player 4: " << players[3] << endl;
        cout << "Player 5: " << players[4] << endl;
        cout << "And the winner is Player " << (maxPlayer+1) << " with a score of " << max << ".";
        cout << endl;

        outFile << " Game " << game << " Score: " << endl;
        outFile << "------------------" << endl;
        outFile << "Player 1: " << players[0] << endl;
        outFile << "Player 2: " << players[1] << endl;
        outFile << "Player 3: " << players[2] << endl;
        outFile << "Player 4: " << players[3] << endl;
        outFile << "Player 5: " << players[4] << endl;
        outFile << "And the winner is Player " << (maxPlayer+1) << " with a score of " << max << ".";
        outFile << endl << endl;

        cout << endl;
        cout << "Keep playing? (y/n): ";
        string answer;
        cin >> answer;
        if (answer == "n")
        {
            done = true;
        }
        else
        {
            game += 1;
        }


    }
    outFile.close();
    system("PAUSE");
    return 0;
}
开发者ID:baw5xc,项目名称:CS-201,代码行数:92,代码来源:main.cpp


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