示例#1
0
文件: main.cpp 项目: krotovss/oop
int main()
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

	ArrayStack<int> s;
	//LinkedStack<int> s;

	const int N = 2;
	for (int i = 0; i < N; ++i)
		s.push(i + 1);

	for (int i = 0; i < N; ++i)
	{
		std::cout << s.peek() << std::endl;
		//s.pop();
	}

	ArrayStack<int> other = s;
	//LinkedStack<int> other = s;
	//other = s;

	s.makeEmpty();

	std::cout << (other.isEmpty() ? 0 : other.peek()) << std::endl;

	std::cout << (s.isEmpty() ? "YES" : "NO") << std::endl;

	return 0;
}
示例#2
0
void main() {

	ArrayStack myArrayStack;

	myArrayStack.isEmpty();

	myArrayStack.Push(45);
	myArrayStack.Push(4);
	myArrayStack.Push(34);
	myArrayStack.Push(99);
	myArrayStack.Push(1200);
	//myArrayStack.Push(771);		//causes stack overflow

	myArrayStack.isEmpty();
	cout << myArrayStack.Size() << endl;

	cout << "\nTop element: " << myArrayStack.Top() << endl;

	cout << "\nRemoving top element: " << myArrayStack.Pop() << endl;

	cout << "\nCurrent top element: " << myArrayStack.Top() << endl;

	cout << myArrayStack.Size() << endl;


	getchar();

}
示例#3
0
int main(){
	ArrayStack s;
	try{
		if(s.isEmpty()){
			cout << "Stack is empty"<< endl;
		}
		
		s.Push(349);
		s.Push(49);
		s.Push(679);
		
		// Print size of stack
		cout << "Size of stack = " << s.Size() << endl;
		
		// Print top element in stack
		cout << "Top Element " << s.Top() << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
		
		// Print popped element from stack
		cout << "Element " << s.Pop() << " popped." << endl;
	}catch(...)
		cout << "Some exception occured." << endl;
	}
	
}
示例#4
0
int main()
{
    int  num;       // the number to be converted
    string numStr;  // string used for input
    int  remainder; // remainder when num is divided by 2
    ArrayStack <int> stackOfRemainders; // remainders
    char response;           // user response
    do
    {
        cout << "Enter positive integer to convert: ";
        cin >> numStr;
        num = atoi(numStr.c_str());
        while (num > 0)
        {
            remainder = num % 2;
            stackOfRemainders.push(remainder);
            num /= 2;
        }

        cout << "Base-two representation: ";
        while ( !stackOfRemainders.isEmpty() )
        {
            remainder = stackOfRemainders.peek();
            stackOfRemainders.pop();
            cout << remainder;
        }
        cout << endl;
        cout << "\nMore (Y or N)? ";
        cin >> response;
    }
    while (response == 'Y' || response == 'y');

    return EXIT_SUCCESS;

}  // end main
示例#5
0
void main(void)
{
    ArrayStack s;
    try{
                if(s.isEmpty()){
                                        cout<<"Stack is empty"<<endl;
                                }
                s.push(200);
                s.push(300);
                cout<<"Size of the stack is: "<<s.size()<<endl;
                cout<<"top is "<<s.Top()<<endl;
                s.pop();
                s.pop();
                cout<<s.isEmpty();
        }
    catch(...){
                cout<<"Some exception occured!!"<<endl;
               }
    getchar();
}