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

📄 service.h

📁 数据结构课程设计 数据结构B+树 B+ tree Library
💻 H
字号:
#include  "insert.h"
#include "limits.h" 

void deal(BTNode *root ,int type)
{
    BTNode *child;
	int find=FALSE;
	int position=0;
	char category;
	int number;
     cout<<"请输入图书编号(比如:A1):";
	 cin>>category;
	 cin>>number;
	 /*cin.clear();  // 清除流的错误标记
      cin.ignore(100, '\n' ); //*/
     child=Search(root,category,position,find);
     switch(type)
     {
     case 1: if(find)//查找
				if(child->books[position]->findNode(number))
					cout<<"\t类别:"<<child->key[position]<<endl<<endl;
				else
					cout<<"此书不存在!"<<endl<<endl;
			 else 
				 cout<<"此书不存在!"<<endl<<endl;       
     break;
     case 2: if(find)//删除
				if(child->books[position]->deleteNode(number))
					cout<<"删除成功!"<<endl<<endl;
				else
					cout<<"此书不存在"<<endl;
			else
				cout<<"此书不存在"<<endl;     
		   break;
     case 3: if(find)//添加
				if(!child->books[position]->findNode(number)) 
					insertBook(child, number,position); 
				else
					cout<<"此书已存在"<<endl<<endl;
			 else 
				 insertCategory(child, number,category,position);     
			break;
	 case 4: if(find) //修改
				if(child->books[position]->modifyNode(number))
					cout<<"修改成功!"<<endl<<endl;
			    else
					cout<<"此书不存在"<<endl<<endl; 
			 else
				cout<<"此书不存在"<<endl<<endl;
				break;
     }

}
void checkBook(BTNode *root)
{
	 deal(root,1);
}
void deleteBook(BTNode *root)
{
	 deal(root,2);
}
void insertBook(BTNode *root)
{
	 deal(root,3);	  
}
void ModifyBook(BTNode *root)
{
     deal(root,4);
}
void service(BTNode *root)
{
   char command;  
   do{       
	   cout<<"查看图书 C"
	   <<"\t添加图书 I"
	   <<"\t删除图书 D"
	   <<"\t修改信息 M"
	   <<"\t退出 Q"
	   <<endl;
      cin>>command; 	   
	  /*cin.clear();  // 清除流的错误标记
      cin.ignore(100, '\n' ); //*/
      switch(command)
	  {
	   case 'c':
	   case 'C':checkBook(root);break;
	   case 'd':
       case 'D':deleteBook(root);break;
	   case 'i':
	   case 'I':insertBook(root);break;
	   case 'm':
       case 'M':ModifyBook(root); break;
	   case 'q':
	   case 'Q':return ;break;
       default: cout<<"命令错误!重新输入"<<endl;	  
	  } 
   }while(command!='Q');
}

⌨️ 快捷键说明

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