?? demodlg.cpp
字號(hào):
// DEMODlg.cpp : implementation file
//
#include "stdafx.h"
#include "DEMO.h"
#include "DEMODlg.h"
#include "stdio.h"
#include "qhncxf_paixu.h"
#define length 100000
#define L 100
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDEMODlg dialog
CDEMODlg::CDEMODlg(CWnd* pParent /*=NULL*/)
: CDialog(CDEMODlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDEMODlg)
m_1 = _T("");
m_2 = _T("");
m_3 = 0;
m_4 = 0;
m_5 = _T("");
m_6 = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON2);
}
void CDEMODlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDEMODlg)
DDX_Text(pDX, IDC_EDIT1, m_1);
DDX_Text(pDX, IDC_jieguo, m_2);
DDX_Text(pDX, IDC_yidong, m_3);
DDX_Text(pDX, IDC_bijiao, m_4);
DDX_Text(pDX, IDC_zhengti_0, m_5);
DDX_Text(pDX, IDC_EDIT2, m_6);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDEMODlg, CDialog)
//{{AFX_MSG_MAP(CDEMODlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_Exit, OnExit)
ON_BN_CLICKED(IDC_Enter, OnEnter)
ON_BN_CLICKED(IDC_re_input, Onreinput)
ON_BN_CLICKED(IDC_Suiji, OnSuiji)
ON_BN_CLICKED(IDC_zhengti_1, Onzhengti1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDEMODlg message handlers
BOOL CDEMODlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CheckRadioButton(IDC_0,IDC_7,IDC_0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CDEMODlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDEMODlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDEMODlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDEMODlg::OnExit()
{
// TODO: Add your control notification handler code here
//退出
MessageBox("感謝您對(duì)本軟件的使用!謝謝","溫馨提示",0);
exit(0);
}
int CDEMODlg::treamform(char *s1, int *s2)
{
/*將字符數(shù)組S1[]的字符轉(zhuǎn)換成整數(shù)存到整形數(shù)組S2[]中*/
int i=0,j=0,d;
char ch;
ch=s1[i]; //ch保存s1串中掃描到的字符,初值為第一個(gè)字符
while(ch!='#')
{
switch (ch)
{
case ' ':
i++;
ch=s1[i];
break;
default:
d=0;
while(ch>='0'&&ch<='9')
{
d=10*d+ch-'0';
i++;
ch=s1[i];
}
s2[j]=d;
j++;
break;
}
}
return j;
}
char s1[length];//存放用戶輸入的排序碼(整型數(shù)據(jù)和空格)
int s2[length]; //將s1中的整型數(shù)據(jù)轉(zhuǎn)換到S2中
void CDEMODlg::OnEnter()
{
// TODO: Add your control notification handler code here
//開始排序
UpdateData(TRUE);
int i,j=0,h=0,k,c=0,m=0;
SortObject st;
if(kaishi())
{
st.n=treamform(s1,s2);
for(i=0;i<st.n;i++)
st.record[i].key=s2[i];
if(st.n==1)
MessageBox("排序碼只有一個(gè)整數(shù)","注意",0);
else
{
h=GetCheckedRadioButton(IDC_0,IDC_7);
if(h==1000)
MessageBox("現(xiàn)是默認(rèn)第一個(gè)排序算法!","說明",0);
switch(h)
{ //MessageBox("請(qǐng)選擇排序算法!","選擇",0);
case 1000:// Shell插入排序
shellSort(st,c,m);break;
case 1001://冒泡排序
bubbleSort( st,c,m );break;
case 1002://快速排序
quickSort(st,0 ,st.n-1,c,m);break;
case 1003://堆排序
heapSort( st,c,m);break;
case 1004://二分法插入排序
binSort ( st,c,m);break;
case 1005://直接插入排序
insertSort(st,c,m);break;
case 1006:// 直接選擇排序
SelectSort(st,c,m);break;
case 1007:
break;
default:break;
}
if(h>=1000&&h<=1007)
{
m_3=m;m_4=c;
m_2="";
int i, s;
char temp[length];
for(i=0;i<st.n;i++)
{
s=st.record[i].key;
itoa(s,temp,10);
m_2=m_2+temp+" ";
}
}
}
}
UpdateData(FALSE);
}
void CDEMODlg::Onreinput()
{
// TODO: Add your control notification handler code here
//重新輸入排序碼
UpdateData(TRUE);
m_1=m_2=m_5="";
m_3=m_4=m_6=0;
ON_IDC_EDIT1:SetFocus();
UpdateData(FALSE);
}
void CDEMODlg::OnSuiji()
{
// TODO: Add your control notification handler code here
//隨機(jī)輸入
UpdateData(TRUE);
int s,i=m_1.GetLength();
if(m_6==0)
{ ON_IDC_EDIT6:SetFocus();
MessageBox("請(qǐng)輸入隨機(jī)輸入的元素個(gè)數(shù)!","注意",0);}
time_t t;
srand((unsigned)time(&t));
char temp[length];
m_1="";
//m_6 random numbers from 0 to 1000\n\n");
for(i=0;i<m_6;i++)
{
s=rand()%1000;
itoa(s,temp,10);
m_1=m_1+temp+" ";
}
UpdateData(FALSE);
}
int CDEMODlg::kaishi()
{
//令字符串的數(shù)字和空格轉(zhuǎn)移到數(shù)組S1中保存
UpdateData(TRUE);
int i,j=0,k;
char ch;
k=m_1.GetLength();
if(k<=0)
{MessageBox("請(qǐng)輸入排序碼!","注意現(xiàn)排序碼為空",0);ON_IDC_EDIT1:SetFocus();return false;}
else
{
for(i=0;i<k;i++)
{
ch=m_1.GetAt(i);
if(ch=='.')
{MessageBox("您輸入的數(shù)據(jù)不符合,請(qǐng)輸入整型數(shù)據(jù)","注意",0);return false;}
if(ch==' '||(ch>='0'&&ch<='9'))
{s1[j]=ch;j++;}
}
s1[j]='#';
return true;
}
UpdateData(FALSE);
}
void CDEMODlg::Onzhengti1()
{
// TODO: Add your control notification handler code here
//整體比較
UpdateData(TRUE);
SortObject st;
int i,j=1;
if(kaishi())
{
st.n=treamform(s1,s2);
if(st.n==1)
MessageBox("排序碼只有一個(gè)整數(shù)","注意",0);
else
{
m_5=m_2="";
while(j<8)
{
for(i=0;i<st.n;i++)
st.record[i].key=s2[i];
int c=0,m=0;
switch(j)
{
case 1:
shellSort(st,c,m);
m_5=m_5+"希爾排序 ";
int i, s;
char temp[length];
for(i=0;i<st.n;i++)
{
s=st.record[i].key;
itoa(s,temp,10);
m_2=m_2+temp+" ";
}
break;
case 2:
bubbleSort( st ,c,m);
m_5=m_5+"冒泡排序 ";
break;
case 3:
quickSort(st,0 ,st.n-1,c,m);
m_5=m_5+"快速排序 ";
break;
case 4:
heapSort( st,c,m);
m_5=m_5+"堆排序 ";
break;
case 5:
binSort ( st,c,m);
m_5=m_5+"二分法插入排序 ";break;
case 6:
insertSort(st,c,m);
m_5=m_5+"直接插入排序 ";break;
case 7:
SelectSort(st,c,m);
m_5=m_5+"直接選擇排序 ";break;
break;
default:
break;
}
j++;
char temp_1[L];
itoa(m,temp_1,10);
m_5=m_5+temp_1+" ";
itoa(c,temp_1,10);
m_5=m_5+temp_1+" ";
}
}
}
UpdateData(FALSE);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -