?? my_b_treeview.cpp
字號:
// My_B_treeView.cpp : implementation of the CMy_B_treeView class
//
//////////////////////////////////////////////////////////////////////////
//姓名: 林文清
//學號: 0610374
//專業: 計算機科學與技術
//課程: 數據結構
//////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "My_B_tree.h"
#include "My_B_treeDoc.h"
#include "My_B_treeView.h"
#include "My_Creat_Btree.h"
#include "My_Fisrt_Insertion.h"
#include "My_Insert_Dlg.h"
#include "My_RemoveDlg.h"
#include "B_tree.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy_B_treeView
IMPLEMENT_DYNCREATE(CMy_B_treeView, CView)
BEGIN_MESSAGE_MAP(CMy_B_treeView, CView)
//{{AFX_MSG_MAP(CMy_B_treeView)
ON_COMMAND(My_Creat_B_tree, OnCreatBtree)
ON_COMMAND(My_Insertion, OnInsertion)
ON_COMMAND(My_Remove, OnRemove)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy_B_treeView construction/destruction
B_tree<int> btree; //聲明B-Tree
CMy_B_treeView::CMy_B_treeView()
{
// TODO: add construction code here
options=0;
whether_created=false;
}
CMy_B_treeView::~CMy_B_treeView()
{
}
BOOL CMy_B_treeView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMy_B_treeView drawing
void CMy_B_treeView::OnDraw(CDC* pDC)
{
CMy_B_treeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
Error_code result;
if (options==1) //創建B-Tree后,打印B-Tree
{
options=0; //將選擇標記清零
My_Creat_Btree mycreatdlg; //打開創建B-Tree的對話框
mycreatdlg.DoModal(); //關掉對話框
int order,num; //階數和初始插入關鍵字的個數
order=mycreatdlg.get_order();//獲取對話框輸入的階數
num=mycreatdlg.get_num(); //獲取對話框輸入的關鍵字的個數
if (order<3||num<0) //若直接關掉對話框
{
AfxMessageBox("Fail to creat B_tree!\norder>=3?\nnum>=0?");
return;
}
whether_created=true; //是否創建B-Tree標記設為"是"
result=btree.set_order(order); //設置B-Tree階數
if (result==duplicate_error) //若已經創建了B-Tree
{
AfxMessageBox("The B_tree have been created!");
}
else //若還沒有創建B-Tree
{
for (int i=0;i<num;i++)
{
My_Fisrt_Insertion myfirstinsertion; //打開初始插入關鍵字的對話框
myfirstinsertion.DoModal();
result=btree.insert(myfirstinsertion.get_key()); //返回插入關鍵字的結果
if (result==duplicate_error) //若要插入的關鍵字在B-Tree中已有
{
AfxMessageBox("Duplicate Error!");
i--; //重新輸入
}
}
}
}
if (options==2) //插入關鍵字
{
options=0; //將選擇標記清零
if (!whether_created) //若還沒有創建B-Tree
{
AfxMessageBox("The B_tree havn't been created!");
}
else //若已經創建B-Tree
{
My_Insert_Dlg myinsertdlg; //打開插入關鍵字的對話框
myinsertdlg.DoModal();
result=btree.insert(myinsertdlg.get_key()); //返回插入關鍵字結果
if (result==duplicate_error) //若重復插入
{
AfxMessageBox("Duplicate Error!");
}
}
}
if (options==3) //刪除關鍵字
{
options=0; //將選擇標記清零
if (!whether_created) //若還沒有創建B-Tree
{
AfxMessageBox("The B_tree havn't been created!");
}
else //若已經創建B-Tree
{
My_RemoveDlg myremovedlg; //打開刪除關鍵字的對話框
myremovedlg.DoModal();
result=btree.remove(myremovedlg.get_key()); //返回刪除關鍵字的結果
if (result!=success) //若刪除不成功
{
AfxMessageBox("The key can't be removed!");
}
}
}
CRect rect;
GetClientRect(rect); //獲取客戶區矩形
CSize size=rect.Size(); //獲取客戶區矩形的大小
CPoint point; //打印B-Tree的起始位置
point.x=size.cx/2;
point.y=5;
btree.display(pDC,point);
}
/////////////////////////////////////////////////////////////////////////////
// CMy_B_treeView printing
BOOL CMy_B_treeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMy_B_treeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMy_B_treeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMy_B_treeView diagnostics
#ifdef _DEBUG
void CMy_B_treeView::AssertValid() const
{
CView::AssertValid();
}
void CMy_B_treeView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMy_B_treeDoc* CMy_B_treeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy_B_treeDoc)));
return (CMy_B_treeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMy_B_treeView message handlers
void CMy_B_treeView::OnCreatBtree()
{
// TODO: Add your command handler code here
options=1;
InvalidateRect(NULL);
}
void CMy_B_treeView::OnInsertion()
{
// TODO: Add your command handler code here
options=2;
InvalidateRect(NULL);
}
void CMy_B_treeView::OnRemove()
{
// TODO: Add your command handler code here
options=3;
InvalidateRect(NULL);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -