コード例 #1
0
int main(){
    //cout<<MIN_INT<<endl;
    StackWithMin mystack;//StackWithMin mystack;
    for(int i=0; i<20; ++i)
        mystack.push(i);
    cout<<mystack.min()<<" "<<mystack.top()<<endl;
    mystack.push(-100);
    mystack.push(-100);
    cout<<mystack.min()<<" "<<mystack.top()<<endl;
    mystack.pop();
    cout<<mystack.min()<<" "<<mystack.top()<<endl;
    return 0;
}
コード例 #2
0
int main(int argc, char* argv []) {
	StackWithMin stack;
	auto list = { 3, 5, 1, 5, 2, 4 };
	for (int n : list) stack.push(n);
	while (!stack.empty()) {
		cout << "v: " << stack.top() << " min: " << stack.min() << endl;
		stack.pop();
	}
	return 0;
}
コード例 #3
0
int main(int argc, char const *argv[])
{
	StackWithMin<int> ss;
	ss.push(4);
	ss.push(9);
	ss.push(1);
	ss.push(11);
	ss.push(6);
	cout << "min:" << ss.min() << endl;
	cout << "top:" << ss.top() << endl;
	ss.pop(); 
	cout << "min:" << ss.min() << endl;
	cout << "top:" << ss.top() << endl;
	if (ss.empty() == true)
	{
		cout << "the stack is empty!" <<endl;
	}
	else
	{
		cout << "the stack is not empty!" <<endl;
		cout << "the stack's size is:" << ss.size() <<endl;
	}
	return 0;
}
コード例 #4
0
int main()
{
	StackWithMin stk;
	for (int i = 0; i < 10; i++)
	{
		int value = rand() % 150;
		cout << "push : " << value << endl;
		stk.push(value);
	}
	cout << "Push 10 Elements and current min is : " << stk.min() << endl << endl;

	for (int i = 0; i < 5; i++)
	{
		int value = stk.top();
		cout << "pop : " << value << endl;
		stk.pop();
	}
	cout << "After pop 5 Elements, current min is : " << stk.min() << endl;
	system("pause");
	return 0;
}
コード例 #5
0
ファイル: tcase1.cpp プロジェクト: pamirs/edo
void verifySolution()
{
StackWithMin<int> stack;

stack.push(5);
CPPUNIT_ASSERT(stack.top() == 5);
CPPUNIT_ASSERT(stack.min() == 5);
stack.push(4);
CPPUNIT_ASSERT(stack.top() == 4);
CPPUNIT_ASSERT(stack.min() == 4);
stack.push(5);
CPPUNIT_ASSERT(stack.top() == 5);
CPPUNIT_ASSERT(stack.min() == 4);
stack.push(2);
CPPUNIT_ASSERT(stack.top() == 2);
CPPUNIT_ASSERT(stack.min() == 2);
stack.pop();
CPPUNIT_ASSERT(stack.top() == 5);
CPPUNIT_ASSERT(stack.min() == 4);
stack.push(3);
CPPUNIT_ASSERT(stack.top() == 3);
CPPUNIT_ASSERT(stack.min() == 3);
stack.push(4);
CPPUNIT_ASSERT(stack.top() == 4);
CPPUNIT_ASSERT(stack.min() == 3);
stack.push(1);
CPPUNIT_ASSERT(stack.top() == 1);
CPPUNIT_ASSERT(stack.min() == 1);
stack.pop();
CPPUNIT_ASSERT(stack.top() == 4);
CPPUNIT_ASSERT(stack.min() == 3);
stack.pop();
CPPUNIT_ASSERT(stack.top() == 3);
CPPUNIT_ASSERT(stack.min() == 3);
stack.pop();
CPPUNIT_ASSERT(stack.top() == 5);
CPPUNIT_ASSERT(stack.min() == 4);
stack.pop();
CPPUNIT_ASSERT(stack.top() == 4);
CPPUNIT_ASSERT(stack.min() == 4);
stack.pop();
CPPUNIT_ASSERT(stack.top() == 5);
CPPUNIT_ASSERT(stack.min() == 5);
stack.push(2);
stack.push(3);
stack.push(2);
stack.push(3);
CPPUNIT_ASSERT(stack.top() == 3);
CPPUNIT_ASSERT(stack.min() == 2);
stack.pop();
CPPUNIT_ASSERT(stack.top() == 2);
CPPUNIT_ASSERT(stack.min() == 2);
stack.pop();
CPPUNIT_ASSERT(stack.top() == 3);
CPPUNIT_ASSERT(stack.min() == 2);
stack.pop();
CPPUNIT_ASSERT(stack.top() == 2);
CPPUNIT_ASSERT(stack.min() == 2);
stack.pop();
CPPUNIT_ASSERT(stack.top() == 5);
CPPUNIT_ASSERT(stack.min() == 5);

auto start = std::chrono::steady_clock::now();
    
	
	auto end = std::chrono::steady_clock::now();
    auto diff = end - start;
    std::cout << std::endl;
    std::cout << "Microseconds: " << std::chrono::duration <double,std::micro> (diff).count() << " us" << std::endl;

}