⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bothstackmain.cpp

📁 数据结构算法集C++版.好东西大家一起分享。
💻 CPP
字号:
//BothStackMain.cpp
#include <iostream>     //进入输入输出流
using namespace std;
#include "BothStack.cpp"  //引入成员函数文件

void main( )
{ 
    BothStack<int> a;             //创建模板类的实例
    
	if (!a.Empty(1)){                //判断栈是否为空
	
	    cout<<"栈1空,对栈1进行压栈操作:"<<endl;
        try
		{
		    a.Push(1,10);
		}
        catch(char* wrong)
		{
			cout<<wrong;
		}
		cout<<"栈1的栈顶元素为:\n";   //读取栈顶元素
		cout<<a.GetTop(1)<<endl;

		cout<<"对栈1进行压栈操作:\n";
		try
		{
			a.Push(1,12);
		}
		catch(char* wrong)
		{
			cout<<wrong;
		}
		cout<<"栈1的栈顶元素为:\n";
		cout<<a.GetTop(1)<<endl;
		
		cout<<"对栈1执行出栈操作:"<<endl; //出栈操作
		a.Pop(1);                     

        cout<<"此时栈1中的栈顶元素为:\n"; 
        cout<<a.GetTop(1)<<endl;
	}
    else{
	
		cout<<"栈1不空"<<endl;
	}
	if (!a.Empty(2)){
	
	    cout<<"栈2空,对栈2进行压栈操作:"<<endl;
    
		try
		{
			a.Push(2,5);
		}
		catch(char* wrong)
		{
			cout<<wrong;
		}
		
		cout<<"栈2的栈顶元素为:\n";
		cout<<a.GetTop(2)<<endl;

		cout<<"对栈2进行压栈操作:\n"; 
		try
		{
			a.Push(2,4);
		}
		catch(char* wrong)
		{
			cout<<wrong;
		}

		cout<<"栈2的栈顶元素为:\n";
		cout<<a.GetTop(2)<<endl;

        cout<<"对栈2进行出栈操作:\n";
        a.Pop(2);

        cout<<"此时栈2中的栈顶元素为:\n"; 
        cout<<a.GetTop(2)<<endl;
		}
   
    else{
	
		cout<<"栈2不空"<<endl;
	}
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -