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

📄 gaokaodlg.cpp

📁 多关键字排序算法,按照多个关键字来排序的算法,关于算法和数据结构的原代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// gaokaoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "gaokao.h"
#include "gaokaoDlg.h"
#include "jiegou.h"    //自己定义的基本数据结构
#include "HelpDlg.h"      //自定义的帮助对话框

#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)
	virtual void OnOK();
	//}}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)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGaokaoDlg dialog

CGaokaoDlg::CGaokaoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGaokaoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGaokaoDlg)
	m_lsd = _T("");
	m_msd = _T("");
	m_select = _T("");
	m_strEdit = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGaokaoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGaokaoDlg)
	DDX_Control(pDX, IDC_SLIDER1, m_Slider1);
	DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
	DDX_Text(pDX, IDC_STATICLSD, m_lsd);
	DDX_Text(pDX, IDC_STATICselect, m_select);
	DDX_Text(pDX, IDC_strEdit, m_strEdit);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGaokaoDlg, CDialog)
	//{{AFX_MSG_MAP(CGaokaoDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_MENUITEM32776, Onshow)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	ON_COMMAND(ID_MENUITEM32772, OnLSD)
	ON_COMMAND(ID_MENUITEM32773, OnSelect)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
	ON_COMMAND(ID_MENUITEM32777, OnMenuitem32777)
	ON_COMMAND(ID_MENUITEM32780, OnMenuitem32780)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_WM_HSCROLL()
	ON_NOTIFY(NM_OUTOFMEMORY, IDC_SLIDER1, OnOutofmemorySlider1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGaokaoDlg message handlers

BOOL CGaokaoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	LV_COLUMN lvColumn;
	lvColumn.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
	lvColumn.fmt=LVCFMT_LEFT;
	lvColumn.cx=60;  //设置列的宽度
	lvColumn.iSubItem=0;
	lvColumn.pszText="姓名";
	m_ListCtrl.InsertColumn(0,&lvColumn);
	lvColumn.iSubItem=1;
	lvColumn.pszText="语文";
	m_ListCtrl.InsertColumn(1,&lvColumn);
	lvColumn.pszText="数学";
	m_ListCtrl.InsertColumn(2,&lvColumn);
	lvColumn.pszText="英语";
	m_ListCtrl.InsertColumn(3,&lvColumn);
	lvColumn.pszText="X科";
	m_ListCtrl.InsertColumn(4,&lvColumn);
	lvColumn.pszText="综合";
	m_ListCtrl.InsertColumn(5,&lvColumn);

	CString str;
	int i,j,score,n;
	srand(time(NULL));
//	n=10+rand()%3;
	n=1000;
	InitSLList(L,n);
	for(i=1;i<=n;i++)
	{
		for(j=0;j<4;j++)
		{
			L.r[i].name[j]=65+rand()%26;
		}
		str.Format("%s",L.r[i].name);
		m_ListCtrl.InsertItem(i-1,str);
		for(j=1;j<=4;j++)
		{
			score=rand()%101;
			if(score<60)                       //if在这里是为了提高整体成绩,不让太多成绩低于60分
			{
				score=rand()%101;
			}
			L.r[i].keys[j]=score;            
			str.Format("%d",L.r[i].keys[j]);
			m_ListCtrl.SetItemText(i-1,j,str);
		}
		L.r[i].keys[5]=L.r[i].keys[1]+L.r[i].keys[2]+L.r[i].keys[3]+L.r[i].keys[4];
		str.Format("%d",L.r[i].keys[5]);
		m_ListCtrl.SetItemText(i-1,j,str);
	}

	copy=L;

	// 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

	////////////////////////////////滑块设置!!!初始化
	m_Slider1.SetRange(0,10000);
	m_Slider1.SetTicFreq(4);
	m_Slider1.SetLineSize(1);
	m_Slider1.SetPageSize(4);
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGaokaoDlg::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 CGaokaoDlg::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 CGaokaoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CGaokaoDlg::Onshow() 
{
	// TODO: Add your command handler code here
	CAboutDlg dlg;
	dlg.DoModal();
	
}

void CGaokaoDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
}

int radio,a=0,b=0,c=0,d=0;
int chosecourse()
{
	if( (a+b+c+d) ==0 ) radio = 0;        //还没有选择要进行排序的关键字
	if( a )          radio = 1;           //选择了chinese
	if( b )          radio = 2;           //选择了math
	if( c )          radio = 3;           //选择了english
	if( d )          radio = 4;           //选择了X科
	return radio;
}


void CGaokaoDlg::OnLSD() 
{
   start=clock();

	int i,j;

	for( i=0 ;  i<L.recnum ;  i++ ) L.r[i].next=i+1;
	L.r[L.recnum].next=0;
	i=chosecourse();
	if(i==0) MessageBox("请先选择关键字!!!");
	else
	{
	RadixSort(L,i);
	RadixSort(L,5);

	m_ListCtrl.DeleteAllItems();         //先清除所有的表现
	for(int k=6;k>=0;k--) m_ListCtrl.DeleteColumn(k);  //再清除所有的列

	LV_COLUMN lvColumn;                                           //设置列表基本信息  列
	lvColumn.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
	lvColumn.fmt=LVCFMT_LEFT;
	lvColumn.cx=60;  //设置列的宽度
	lvColumn.iSubItem=0;
	lvColumn.pszText="姓名";
	m_ListCtrl.InsertColumn(0,&lvColumn);
	lvColumn.iSubItem=1;
	lvColumn.pszText="语文";
	m_ListCtrl.InsertColumn(1,&lvColumn);
	lvColumn.pszText="数学";
	m_ListCtrl.InsertColumn(2,&lvColumn);
	lvColumn.pszText="英语";
	m_ListCtrl.InsertColumn(3,&lvColumn);
	lvColumn.pszText="X科";
	m_ListCtrl.InsertColumn(4,&lvColumn);
	lvColumn.pszText="综合";
	m_ListCtrl.InsertColumn(5,&lvColumn);
	lvColumn.pszText="排名";
	m_ListCtrl.InsertColumn(6,&lvColumn);


	CString str;
 
	for(k=0,i=L.r[0].next; i; i=L.r[i].next,k++ )
	{
		str.Format("%s",L.r[i].name);
		m_ListCtrl.InsertItem(k,str);
		for(j=1;j<=4;j++)
		{			        
			str.Format("%d",L.r[i].keys[j]);

⌨️ 快捷键说明

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