Exemplo n.º 1
0
void pushItem(DynamicStack<string> &stack)
{
    string item;
    cin.ignore();
    cout<<"\nEnter an item ";
    getline(cin,item);
    stack.push(item);
}
Exemplo n.º 2
0
void test2()
{
	DynamicStack<int> iStack;

	iStack.push(1);
	iStack.push(2);
	iStack.push(3);
	iStack.push(4);
	iStack.push(5);
	iStack.push(6);

	cout << "Traverse elements" << endl;

	for(DynamicStackIterator<int> iter = DynamicStackIterator<int>(iStack); iter != iter.end(); iter++){
		cout << "value: " << *iter << endl;
	}
}
Exemplo n.º 3
0
	// Full stack doubles properly
	bool test5() {
	     DynamicStack stack;
	     for(int i = 0; i < 17; i++)
	             stack.push(i);
	     ASSERT_TRUE(stack.capacity_ == 32)
	     for(int i = 16; i >= 0; i--)
	             ASSERT_TRUE(stack.pop() == i)
	     ASSERT_TRUE(stack.pop() == DynamicStack::EMPTY_STACK)
	     return true;
	}
Exemplo n.º 4
0
	// Push one item and then pop it
    bool test2() {
	      DynamicStack stack;
	      stack.push(10);
	      ASSERT_TRUE(stack.empty() == false)
	      ASSERT_TRUE(stack.size() == 1)       
	      ASSERT_TRUE(stack.pop() == 10);
	      ASSERT_TRUE(stack.empty() == true)
	      ASSERT_TRUE(stack.size() == 0)     
	      return true;
    }
Exemplo n.º 5
0
	// Push a number of items equal to initial size + 1 and then remove slightly more than half of them so that 
	//no. of items is less than half the new size of the stack. The size limit should be halved by then
	bool test8() {
	     DynamicStack stack;
	     for(int i = 0; i < 17; i++)
	             stack.push(i);
	     ASSERT_TRUE(stack.capacity_ == 32)
	     for(int i = 16; i >= 6; i--)
	             ASSERT_TRUE(stack.pop() == i)
	     ASSERT_TRUE(stack.capacity_ == 16)
	     return true;
	}
Exemplo n.º 6
0
	// Push a number of items equal to initial size and then remove most of them so that no. of items 
	//is less than half the size of the stack. As the size limit is still the initial size, no 
	//changes in its value should take place
	bool test7() {
	     DynamicStack stack;
	     for(int i = 0; i < 16; i++)
	             stack.push(i);
	     ASSERT_TRUE(stack.capacity_ == 16)
	     for(int i = 15; i >= 1; i--)
	             ASSERT_TRUE(stack.pop() == i)
	     ASSERT_TRUE(stack.capacity_ == 16)
	     ASSERT_TRUE(stack.size() == 1)
	     return true;
	}
Exemplo n.º 7
0
void test1()
{
	DynamicStack<int> iStack;

	iStack.push(1);
	iStack.push(2);
	iStack.push(3);
	iStack.push(4);
	iStack.push(5);
	iStack.push(6);

	cout << "top: " << iStack.top() << endl;
	iStack.pop();
	iStack.pop();
	cout << "top: " << iStack.top() << endl;
	iStack.pop();
	cout << "top: " << iStack.top() << endl;
	cout << "size: " << iStack.size() << endl;
	cout << "is empty: " << (iStack.isEmpty() ? "T" : "F") << endl;
	iStack.pop();
	iStack.pop();
	iStack.pop();
	cout << "is empty: " << (iStack.isEmpty() ? "T" : "F") << endl;
}