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;
}
Esempio n. 2
0
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();
}
Esempio n. 3
0
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();
}
Esempio n. 4
0
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();
}
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;
}
Esempio n. 6
0
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;
}