📄 bubblesortview.cpp
字号:
// BubbleSortView.cpp : implementation of the CBubbleSortView class
//
#include "stdafx.h"
#include "BubbleSort.h"
#include "BubbleSortDoc.h"
#include "BubbleSortView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBubbleSortView
IMPLEMENT_DYNCREATE(CBubbleSortView, CView)
BEGIN_MESSAGE_MAP(CBubbleSortView, CView)
//{{AFX_MSG_MAP(CBubbleSortView)
ON_COMMAND(ID_BUBBLESORT, OnBubblesort)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CBubbleSortView construction/destruction
CBubbleSortView::CBubbleSortView()
{
// TODO: add construction code here
}
CBubbleSortView::~CBubbleSortView()
{
}
BOOL CBubbleSortView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CBubbleSortView drawing
void CBubbleSortView::OnDraw(CDC* pDC)
{
CBubbleSortDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
for(int i=0;i<szList.GetCount();i++)
{
if(i<25)
pDC->TextOut(20,2+14*i,szList.GetAt(szList.FindIndex(i)));
else
pDC->TextOut(280,2+14*(i-25),szList.GetAt(szList.FindIndex(i)));
}
}
/////////////////////////////////////////////////////////////////////////////
// CBubbleSortView printing
BOOL CBubbleSortView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CBubbleSortView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CBubbleSortView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CBubbleSortView diagnostics
#ifdef _DEBUG
void CBubbleSortView::AssertValid() const
{
CView::AssertValid();
}
void CBubbleSortView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CBubbleSortDoc* CBubbleSortView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBubbleSortDoc)));
return (CBubbleSortDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBubbleSortView message handlers
void CBubbleSortView::OnBubblesort()
{
// TODO: Add your command handler code here
char buffer[20];
CString szTemp;
int i=0,j=0;
int temp;
int nSort[10]={0,7,3,9,2,4,8,1,6,5};
szTemp=" ";
for(int k=0;k<10;k++)
{
_itoa(nSort[k],buffer,10);
szTemp+=buffer;
szTemp+=" ";
}
szList.AddTail(szTemp);
for(i=0;i<9;i++)
for(j=9;j>i;j--)
{
if(nSort[j]<nSort[j-1])
{
temp=nSort[j];
nSort[j]=nSort[j-1];
nSort[j-1]=temp;
}
szTemp=" ";
for(int k=0;k<10;k++)
{
_itoa(nSort[k],buffer,10);
szTemp+=buffer;
szTemp+=" ";
}
szList.AddTail(szTemp);
Invalidate();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -