📄 baizheshudlg.cpp
字号:
// baizheshuDlg.cpp : implementation file
//
#include "stdafx.h"
#include "baizheshu.h"
#include "baizheshuDlg.h"
#include<math.h>
#include "c10-1.h"
#include "c9-7.h"
#include "bo10-1.c"
#include "c1.h"
#include "MyList.h"
SqList H[5];
RedType b[5];//败者树中的叶子结点
RedType c[5];//败者树中的非叶子结点
int temp6=0;//为列表控件的行计数
LoserTree ls;
POINT p[9];//各结点的坐标值
int r;
int X,Y;
double R;
int x,y;
int flag;//暂停标志
int FLAG;//字符串转移方向标志
int tt;//多线程传递参数
int C;//控制线程中的循环
int D;
CString STR;
#define N 5;
#define K 5;//k路归并
//const K 5;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CBaizheshuDlg* m_pOwner;
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()
/////////////////////////////////////////////////////////////////////////////
// CBaizheshuDlg dialog
CBaizheshuDlg::CBaizheshuDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBaizheshuDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBaizheshuDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CBaizheshuDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBaizheshuDlg)
DDX_Control(pDX, IDCANCLE, m_zt);
DDX_Control(pDX, IDC_LIST1, m_MyList6);
DDX_Control(pDX, IDC_LIST5, m_MyList4);
DDX_Control(pDX, IDC_LIST6, m_MyList5);
DDX_Control(pDX, IDC_LIST4, m_MyList3);
DDX_Control(pDX, IDC_LIST3, m_MyList2);
DDX_Control(pDX, IDC_LIST2, m_MyList1);
DDX_Control(pDX, IDC_SLIDER1, m_ss);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBaizheshuDlg, CDialog)
//{{AFX_MSG_MAP(CBaizheshuDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDCANCLE, OnControl)
ON_BN_CLICKED(IDC_BUTTON3, OnOK)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBaizheshuDlg message handlers
BOOL CBaizheshuDlg::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
CRect rect;
ShowWindow(SW_SHOWMAXIMIZED); // 最大化窗口
GetClientRect(rect); // 得到对话框的窗口尺寸并赋给rect(左上角为0,0)
Dialog.x=rect.right; // 将对话框的窗口尺寸赋给全局坐标量Dialog
Dialog.y=rect.bottom;
r=20;//半径
int cc,bb,m,j,ww,pp,qq,flag=0;
FILE *fg;
FILE *f[5];
fg=fopen("f0.txt","r");// 打开数据文件,并以fg表示
f[0]=fopen("f1.txt","w");
f[1]=fopen("f2.txt","w");
f[2]=fopen("f3.txt","w");
f[3]=fopen("f4.txt","w");
f[4]=fopen("f5.txt","w");
if(fg)
{
do
{
bb=fscanf(fg,"%d",&j); // 将文件f0.txt中的整数赋给j
if(bb==EOF)
break;
flag++;//对文件所含元素计数
} while(1);
fclose(fg); // 关闭fp所指的文件,fp不再指向f0.txt文件
}
ww=flag/2/K;
qq=flag/2%K;
fg=fopen("f0.txt","r");// 打开数据文件,并以fg表示
if (fg)
{
if(qq==0)//如果f0.txt所包含的记录刚好为K的整数倍
{
for( m=0;m<5;m++)
{
for( pp=0;pp<ww*2;pp++)
{
fscanf(fg,"%d",&j); // 将文件f0.txt中的整数赋给j
if(pp%2==0)//每个记录的第一个数据项
{
cc=pp/2;
H[m].r[cc+1].key=j;
fprintf(f[m],"%d",j);//将此数据项输出到小文件中
}
else//每个记录的第二个数据项
{
cc=pp/2;
H[m].r[cc+1].otherinfo=j;
fprintf(f[m]," %d\n",j);
}
}//end for
H[m].length=ww;//小文件的长度
}//end for
}//end if
else//如果f0.txt所包含的记录数不是K的整数倍
{
for( m=0;m<5;m++)
{
if (m<=(qq-1) )
{
for( pp=0;pp<(ww+1)*2;pp++)//前 qq个小文件包含(ww+1)*2个数据项
{
fscanf(fg,"%d",&j); // 将文件f0.txt中的整数赋给j
if(pp%2==0)
{
cc=pp/2;
H[m].r[cc+1].key=j;
fprintf(f[m],"%d",j);
}
else
{
cc=pp/2;
H[m].r[cc+1].otherinfo=j;
fprintf(f[m]," %d\n",j);
}
}//end for
H[m].length=(ww+1);
}//end if
else
{
for(pp=0;pp<ww*2;pp++)//剩下的文件包含(ww+1)*2个数据项
{
fscanf(fg,"%d",&j); // 将文件f0.txt中的整数赋给j
if(pp%2==0)
{
cc=pp/2;
H[m].r[cc+1].key=j;
fprintf(f[m]," %d",j);
}
else
{
cc=pp/2;
H[m].r[cc+1].otherinfo=j;
fprintf(f[m]," %d\n",j);
}
}//end for
H[m].length=ww;
}//end else
}//end for
}//end else
}//end if
fclose(fg); // 关闭fp所指的文件,fp不再指向f0.txt文件
for(m=0;m<5;m++)
InsertSort(H[m]);//对五个小文件进行内部排序
DWORD ExStyle =m_MyList1.GetExtendedStyle();
m_MyList1.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); // 设置为整栏选择和网格线
// m_MyList1.SetBkColor(RGB(230,230,230)); // 设置控件背景色
ExStyle =m_MyList2.GetExtendedStyle();
m_MyList2.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); // 设置为整栏选择和网格线
ExStyle =m_MyList3.GetExtendedStyle();
m_MyList3.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); // 设置为整栏选择和网格线
ExStyle =m_MyList4.GetExtendedStyle();
m_MyList4.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); // 设置为整栏选择和网格线
ExStyle =m_MyList5.GetExtendedStyle();
m_MyList5.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); // 设置为整栏选择和网格线
ExStyle =m_MyList6.GetExtendedStyle();
m_MyList6.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); // 设置为整栏选择和网格线
m_MyList1.InsertColumn(0,"关键字",LVCFMT_CENTER,50,-1); // 0:列号;"名称":列标题
m_MyList1.InsertColumn(1,"顺序",LVCFMT_CENTER,50,-1); // LVCFMT_LEFT:左对齐,也可选LVCFMT_
m_MyList2.InsertColumn(0,"关键字",LVCFMT_CENTER,50,-1); // 0:列号;"名称":列标题
m_MyList2.InsertColumn(1,"顺序",LVCFMT_CENTER,50,-1); // LVCFMT_LEFT:左对齐,也可选LVCFMT_RIGHT, LVCFMT_CENTER
m_MyList3.InsertColumn(0,"关键字",LVCFMT_CENTER,50,-1); // 0:列号;"名称":列标题
m_MyList3.InsertColumn(1,"顺序",LVCFMT_CENTER,50,-1); // LVCFMT_LEFT:左对齐,也可选LVCFMT_RIGHT, LVCFMT_CENTER
m_MyList4.InsertColumn(0,"关键字",LVCFMT_CENTER,50,-1); // 0:列号;"名称":列标题
m_MyList4.InsertColumn(1,"顺序",LVCFMT_CENTER,50,-1); // LVCFMT_LEFT:左对齐,也可选LVCFMT_RIGHT, LVCFMT_CENTER
m_MyList5.InsertColumn(0,"关键字",LVCFMT_CENTER,50,-1); // 0:列号;"名称":列标题
m_MyList5.InsertColumn(1,"顺序",LVCFMT_CENTER,50,-1); // LVCFMT_LEFT:左对齐,也可选LVCFMT_RIGHT, LVCFMT_CENTER
m_MyList6.InsertColumn(0,"关键字",LVCFMT_CENTER,50,-1); // 0:列号;"名称":列标题
m_MyList6.InsertColumn(1,"顺序",LVCFMT_CENTER,50,-1); // LVCFMT_LEFT:左对齐,也可选LVCFMT_RIGHT, LVCFMT_CENTER
data();
m_pOwner=this; // m_pOwner指向本对话框
hWnd=GetSafeHwnd();
UpdateData(FALSE); // 刷新对话框
m_ss.SetRangeMin(0); // 最小值
m_ss.SetRangeMax(2000); // 最大值
m_ss.SetPos(400); // 初始位置
m_ss.SetTicFreq(2); // 标记间隔
return TRUE; // return TRUE unless you set the focus to a control
}
void CBaizheshuDlg::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 CBaizheshuDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (IsIconic())
{
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
{
dc.SetTextAlign(TA_CENTER); // 设置文本居中
dc.SetBkMode(TRANSPARENT); // 设置文本的背景为透明
dc.SelectStockObject(NULL_BRUSH); // 设置图形填充为透明
CBrush br,br1,*pbr;
br.CreateSolidBrush(RGB(245,73,99));
br1.CreateSolidBrush(RGB(0,255,255));
double ViewY; // 视图纵向占屏幕的百分比
double ViewX; // 视图横向占屏幕的百分比
int t,i,j;
t=int(log(10)/log(2))+1;//败者树的层数
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -