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

📄 bfsearchdlg.cpp

📁 数据结构(C++版)的演示程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// BFSearchDlg.cpp : implementation file
//

#include "stdafx.h"
#include "BFSearch.h"
#include "BFSearchDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBFSearchDlg dialog

CBFSearchDlg::CBFSearchDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBFSearchDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBFSearchDlg)
	m_ValueShow1 = _T("");
	m_ValueShow2 = _T("");
	m_ValueShow3 = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CBFSearchDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBFSearchDlg)
	DDX_Text(pDX, IDC_VALUE_SHOW1, m_ValueShow1);
	DDX_Text(pDX, IDC_VALUE_SHOW2, m_ValueShow2);
	DDX_Text(pDX, IDC_VALUE_SHOW3, m_ValueShow3);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBFSearchDlg, CDialog)
	//{{AFX_MSG_MAP(CBFSearchDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_AUTO_STEP, OnAutoStep)
	ON_BN_CLICKED(IDC_SINGLE_STEP, OnSingleStep)
	ON_BN_CLICKED(IDC_END_SHOW, OnEndShow)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBFSearchDlg message handlers

CBFSearchDlg::~CBFSearchDlg()
{
	delete G;
	delete m_pQ;
	delete m_pCodeDisplayWnd;
	delete m_pQueueDisplayWnd;
	delete m_pMoveDisplayWnd;
	if(m_pShowThread)
	{
		delete m_pShowThread;
		m_pShowThread = NULL;
	}
}

CDialog * CBFSearchDlg::GetDlg()
{
	CBFSearchApp *pApp = (CBFSearchApp *)AfxGetApp();
	CDialog *pDialog = (CDialog *)pApp->m_pMainWnd;
	return pDialog;
}


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

	// 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
	G = new CGraph;
	m_pQ = new CQueue(20);
	m_dlg.m_G = G;
	if(m_dlg.DoModal()==IDCANCEL)
		CDialog::OnCancel();

	RECT rect;
	m_pCodeDisplayWnd= new CTextWnd(IDC_CODE_SHOW);
	m_pCodeDisplayWnd->Create(NULL,NULL,WS_CHILD|WS_VISIBLE,rect,this,0,NULL);
	m_pQueueDisplayWnd= new CTextWnd(IDC_QUEUE_SHOW);
	m_pQueueDisplayWnd->Create(NULL,NULL,WS_CHILD|WS_VISIBLE,rect,this,0,NULL);
	m_pMoveDisplayWnd= new CMoveWnd(IDC_MOVE_SHOW, G);
	m_pMoveDisplayWnd->Create(NULL,NULL,WS_CHILD|WS_VISIBLE,rect,this,0,NULL);
	
	SetCodeSentence();
	m_pQueueDisplayWnd->SetTextWnd();
//	m_pMoveDisplayWnd->SetMoveWnd();
	m_Break = FALSE;
	mExist = FALSE;
	mAuto = FALSE;
	mEnd = TRUE;
	m_pShowThread = NULL;

	return TRUE;  // return TRUE  unless you set the focus to a control
}

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


void CBFSearchDlg::SetCode(int pos)////////////////////////////////////////
{
	for(int i=0; i<m_pCodeDisplayWnd->m_Sentence_num; i++)
		if(m_pCodeDisplayWnd->m_Sentence_Flag[i] == 'L')
			m_pCodeDisplayWnd->m_Sentence_Flag[i] ='A';
	m_pCodeDisplayWnd->m_Sentence_Flag[pos] = 'L';
	m_pCodeDisplayWnd->Invalidate();
}

void CBFSearchDlg::enQueue(CString CallStr, int v)
{
	if(m_lastV != v)
	{
		G->SetEdge(v, m_lastV, 2);
		G->SetEdge(m_lastV, v, 2);
	}
	m_pQueueDisplayWnd->m_Sentence[m_pQueueDisplayWnd->m_Sentence_num].Empty();
	m_pQueueDisplayWnd->m_Sentence[m_pQueueDisplayWnd->m_Sentence_num] += CallStr;
	if(m_pQueueDisplayWnd->m_Sentence_num == 0)	
		m_pQueueDisplayWnd->m_Sentence_Flag[m_pQueueDisplayWnd->m_Sentence_num] = 'L';
	else
		m_pQueueDisplayWnd->m_Sentence_Flag[m_pQueueDisplayWnd->m_Sentence_num] = 'A';
	m_pQueueDisplayWnd->m_Sentence_num++;
	m_pQueueDisplayWnd->Invalidate();
}

void CBFSearchDlg::deQueue()
{
	int i;

	m_pQueueDisplayWnd->m_Sentence_num--;
	for(i=0; i<m_pQueueDisplayWnd->m_Sentence_num; i++)
	{
		m_pQueueDisplayWnd->m_Sentence[i].Empty();
		m_pQueueDisplayWnd->m_Sentence[i] += m_pQueueDisplayWnd->m_Sentence[i+1];
	    m_pQueueDisplayWnd->m_Sentence_Flag[i] = 'A';
	}
	m_pQueueDisplayWnd->m_Sentence[m_pQueueDisplayWnd->m_Sentence_num].Empty();
	m_pQueueDisplayWnd->m_Sentence_Flag[0] = 'L';
	m_pQueueDisplayWnd->Invalidate();
}

void CBFSearchDlg::SetMoveValue()
{
	m_pMoveDisplayWnd->Invalidate();
	if(mAuto == TRUE)
		Sleep(500);
}

BOOL CBFSearchDlg::SetValue(int start, int v, int w, int n, int length, int markW, int firstV, int nextV)
{
	if(m_Break == TRUE)
		return TRUE;
	CString str;
	m_ValueShow1.Empty();
	if(v < 0)
		m_ValueShow1.Format("start=%d, v=错误!, ", start);
	else
		m_ValueShow1.Format("start=%d, v=%d, ", start, v);
	if(w < 0)
		str.Format("w=错误!\n");
	else
		str.Format("w=%d\n", w);
	m_ValueShow1 += str;

	m_ValueShow2.Empty();
	if(n < 0)
		m_ValueShow2.Format("G->n( )=错误!, Q->length()=%d\n", length);
	else
		m_ValueShow2.Format("G->n( )=%d, Q->length()=%d\n", n, length);

	
	
	m_ValueShow3.Empty();
	if(markW < 0)
		m_ValueShow3.Format("G->getMark(w)=错误!, ");
	else
		m_ValueShow3.Format("G->getMark(w)=%d, ", markW);
	if(firstV < 0)
		str.Format("G->first(v)=错误!, ");
	else
		str.Format("G->first(v)=%d, ", firstV);
	m_ValueShow3 += str;
	if(nextV < 0)
		str.Format("G->next(v, w)=错误!\n");
	else
		str.Format("G->next(v, w)=%d\n", nextV);
	m_ValueShow3 += str;

	Invalidate();

	if(mAuto==FALSE)
	{
		WaitForSingleObject(mStepEvent, INFINITE);
		mStepEvent.ResetEvent();
	}
	return FALSE;
}


void CBFSearchDlg::ResetMoveWnd()
{
//	m_pMoveDisplayWnd->SetMoveWnd(m_A, m_temp, m_count);
	int i, j;
	for(i=0; i<m_pMoveDisplayWnd->m_pG->n(); i++)
		for(j=0; j<m_pMoveDisplayWnd->m_pG->n(); j++)
			if(m_pMoveDisplayWnd->m_pG->getEdge(i, j) > 1)
				m_pMoveDisplayWnd->m_pG->SetEdge(i, j, 1);
	m_pMoveDisplayWnd->Invalidate();
}

void CBFSearchDlg::ResetCodeSentence()
{
	m_pCodeDisplayWnd->m_Sentence_Flag[0] = 'L';
	memcpy(m_pCodeDisplayWnd->m_Pos_Flag, " ● ", 4);
	for(int i=1; i<m_pCodeDisplayWnd->m_Sentence_num; i++)
		if(m_pCodeDisplayWnd->m_Sentence_Flag[i] == 'L')
			m_pCodeDisplayWnd->m_Sentence_Flag[i] = 'A';
	m_ValueShow1.Empty();
	m_ValueShow2.Empty();
	m_ValueShow3.Empty();
	m_pCodeDisplayWnd->Invalidate();
}
void CBFSearchDlg::ResetQueueSentence()
{
	memcpy(m_pQueueDisplayWnd->m_Pos_Flag, "队头", 4);
	m_pQueueDisplayWnd->m_ResetWnd = TRUE;
	for(int i=0; i<m_pQueueDisplayWnd->m_Sentence_num; i++)
		m_pQueueDisplayWnd->m_Sentence[i].Empty();
	m_pQueueDisplayWnd->m_Sentence_num = 0;
	m_pQueueDisplayWnd->Invalidate();
}

⌨️ 快捷键说明

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