数据结构Word文档下载推荐.docx
- 文档编号:18482690
- 上传时间:2022-12-17
- 格式:DOCX
- 页数:16
- 大小:20.78KB
数据结构Word文档下载推荐.docx
《数据结构Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《数据结构Word文档下载推荐.docx(16页珍藏版)》请在冰豆网上搜索。
∙virtual~CDiGraph();
∙基本数据:
∙voidDrawFloyd(CDC*pDC);
∙voidFloyd();
∙voidTransform();
∙voidInitHand();
∙//有向图的当前顶点数目
∙intvexnum;
∙//有向图的当前边数目
∙intarcnum;
∙//有向图深度优先已经遍历顶点数目
∙intm_nDFSnum;
∙//有向图存储链表
∙CTypedPtrList<
CObList,CGraphVertex*>
m_DigraphList;
∙CStringArrayvex[MAX];
∙intArrayweight[MAX][MAX];
∙CStringPath[MAX][MAX];
基本操作:
voidCreateDGRandom(CPointvCenterPoint);
//自动创建有向图
voidCreateDGHand(CPointvCenterPoint);
//手动创建有向图
///////////////////////////////////////////////////////
//有向图基本函数//
///////////////////////////////////////////////////////
intLocateInList(CStringvName);
//判断顶点vPoint是否在有向图存储链表
CGraphVertex*IsPointInList(CPointvPoint);
//判断顶点名vName是否在有向图存储链表
CGraphVertex*IsNameInList(CStringvName);
//判断边(pBeginVex,pEndVex)是否在有向图中
BOOLIsEdgeExist(CGraphVertex*pBeginVex,CGraphVertex*pEndVex);
//判断名为vName的顶点是否在有向图中存储链表中
CGraphVertex*IsVexNameInList(CStringvName);
//查找名为vName的顶点在有向图中存储链表中的地址
CGraphVertex*FindVexNameInList(CStringvName);
//设置边(vBeginVex,vEndVex)的权值
voidSetEdgeWeight(CStringvBeginVex,CStringvEndVex,intvWeight);
voidDeleteVex(CPointvPoint);
//删除显示位置为vPoint的顶点
voidDeleteEdge(CGraphVertex*pBeginVex,CGraphVertex*pEndVex);
//删除边(pBeginVex,pEndVex)
voidInsertEdge(CGraphVertex*pBeginVex,CGraphVertex*pEndVex,intweight);
//插入顶点(pBeginVex,pEndVex)之间的边
//有向图显示函数//
//有向图可视化显示
voidDrawDiGraph(CDC*pDC);
//显示有向图边
voidDrawEdges(CDC*pDC);
//显示有向图顶点
voidDrawVexs(CDC*pDC);
∙};
画图类:
∙classCDiGraphDraw:
publicCFormView
∙protected:
∙CDiGraphDraw();
//protectedconstructorusedbydynamiccreation
∙DECLARE_DYNCREATE(CDiGraphDraw)
∙
∙//FormData
∙//{{AFX_DATA(CDiGraphDraw)
∙enum{IDD=IDD_DIGRHDRAW_FORMVIEW};
∙//NOTE:
theClassWizardwilladddatamembershere
∙//}}AFX_DATA
∙//Attributes
∙//Operations
∙voidDrawFloyd(CDC*pDC);
∙//画出弗洛伊德算法的结果
∙voidSetEdgeWeightHand();
∙//手动设置权值
∙voidDelEdgesHand();
∙//手动删除边
∙voidAddEdgesHand();
∙//手动添边
∙voidMovVertsHand();
∙BOOLm_Capture;
∙voidDelVertsHand();
∙//手动删除顶点
∙voidAddVertsHand();
∙//手动添加顶点
∙voidCreateDGHand();
∙//手动创建有向图
∙voidCreateDGRandom();
∙//自动创建有向图
∙voidComputeFloyd();
∙CGraphVertex*m_pEndNode;
∙CGraphVertex*m_pBeginNode;
∙CPointm_StartPoint;
∙intm_FunType;
∙voidDrawDGHand(CDC*pDC);
∙voidDrawDGRandom(CPointvCenterPoint,CDC*pDC);
∙staticDWORDWINAPIDiGraphproc(LPVOIDlpParameter);
∙CDataStructVisualDoc*GetDocument();
∙CDataStructVisualDoc*pDoc;
∙boolm_StartFlag;
∙HANDLEhEventDiGraph;
∙HANDLEhThreadDiGraph;
∙intm_flag;
∙有向图边的类:
∙classCGraphEdge:
publicCObject
∙CGraphEdge();
∙virtual~CGraphEdge();
∙boolEdgeDraw(CGraphVertex*pBeginVex,CDC*pDC);
∙intinfo;
∙intm_weight;
//边的权值
∙COLORREFm_color;
//图边颜色
∙CGraphVertex*m_pAdjVertex;
∙CGraphEdge*m_pNextEdge;
∙}
∙有向图顶点的类:
∙classCGraphVertex:
publicCObject
∙CGraphVertex();
∙virtual~CGraphVertex();
∙boolVexDraw(CDC*pDC);
∙CPointm_point;
//图顶点颜色
∙CGraphEdge*m_pFirstEdge;
∙charm_strname;
∙BOOLm_bvisit;
∙intm_nvisit;
∙intm_pos;
∙弗洛伊德算法及其画图的代码:
∙voidCDiGraph:
:
Floyd()
∙Transform();
∙intA[MAX][MAX];
∙inti,j,k;
∙for(i=0;
i<
vexnum;
i++)
∙{
∙for(j=0;
j<
j++)
∙{
∙A[i][j]=Arrayweight[i][j];
∙if(A[i][j]!
=0&
&
A[i][j]<
INT_MAX)
∙{
∙Path[i][j]=Arrayvex[i]+Arrayvex[j];
∙}
∙}
∙}
∙for(k=0;
k<
k++)
∙for(i=0;
∙for(j=0;
∙if(A[i][j]>
(A[i][k]+A[k][j]))
∙{
∙if(A[i][k]<
INT_MAX&
A[k][j]<
∙{
∙A[i][j]=A[i][k]+A[k][j];
∙if(Path[i][k]!
='
0'
Path[k][j]!
)
∙{
∙Path[i][j]=Path[i][k]+Arrayvex[j];
∙}
∙
∙}
∙}
∙Arrayweight[i][j]=A[i][j];
DrawFloyd(CDC*pDC)
∙CStringstr;
∙m_point.y=50;
∙m_point.x=700;
∙pDC->
MoveTo(m_point.x,m_point.y);
LineTo(m_point.x-10,m_point.y+10);
MoveTo(m_point.x-10,m_point.y+10);
LineTo(m_point.x-10,m_point.y+vexnum*20-10);
MoveTo(m_point.x-10,m_point.y+vexnum*20-10);
LineTo(m_point.x,m_point.y+vexnum*20);
∙for(inti=0;
∙m_point.x=700;
∙for(intj=0;
∙if(Arrayweight[i][j]<
∙str.Format("
%d"
Arrayweight[i][j]);
∙pDC->
TextOut(m_point.x,m_point.y,str);
∙m_point.x+=20;
∙else
Arrayweight[0][0]);
∙m_point.y+=20;
MoveTo(m_point.x-10,m_point.y);
LineTo(m_point.x,m_point.y-10);
MoveTo(m_point.x,m_point.y-10);
LineTo(m_point.x,m_point.y-vexnum*20+10);
MoveTo(m_point.x,m_point.y-vexnum*20+10);
LineTo(m_point.x-10,m_point.y-vexnum*20);
∙m_point.y=250;
%s"
Path[i][j]);
∙m_point.x+=45;
∙界面显示:
∙classCLeftPane:
∙CLeftPane();
∙DECLARE_DYNCREATE(CLeftPane)
∙//{{AFX_DATA(CLeftPane)
∙enum{IDD=IDD_LEFTPANE_FORMVIEW};
∙CTreeCtrlm_LeftTree;
∙CRightFrame*m_pRightSwitchFrame;
∙//Overrides
∙//ClassWizardgeneratedvirtualfunctionoverrides
∙//{{AFX_VIRTUAL(CLeftPane)
∙public:
∙virtualvoidOnInitialUpdate();
∙protected:
∙virtualvoidDoDataExchange(CDataExchange*pDX);
//DDX/DDVsupport
∙virtualvoidCalcWindowRect(LPRECTlpClientRect,UINTnAdjustType=adjustBorder);
∙//}}AFX_VIRTUAL
∙//Implementation
∙virtual~CLeftPane();
∙#ifdef_DEBUG
∙virtualvoidAssertValid()const;
∙virtualvoidDump(CDumpContext&
dc)const;
∙#endif
∙//Generatedmessagemapfunctions
∙//{{AFX_MSG(CLeftPane)
∙afx_msgvoidOnSize(UINTnType,intcx,intcy);
∙afx_msgvoidOnCancelMode();
∙afx_msgvoidOnSelchangedLeftpaneTree(NMHDR*pNMHDR,LRESULT*pResult);
∙//}}AFX_MSG
∙DECLARE_MESSAGE_MAP()
∙private:
∙voidInitTree();
∙HTREEITEMm_Root;
∙CImageListm_TreeImageList;
∙CRectm_sRect;
树的显示:
∙voidCLeftPane:
InitTree()
∙LPSTRpszText;
∙m_TreeImageList.Create(16,16,TRUE,6,1);
∙HICONhIcon;
∙hIcon=:
LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1));
∙m_TreeImageList.Add(hIcon);
LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON2));
LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON3));
LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON4));
LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON5));
∙m_LeftTree.SetImageList(&
m_TreeImageList,TVSIL_NORMAL);
∙//////////////////////在树视图控件添加信息/////////////////////////////////////
∙m_LeftTree.DeleteAllItems();
//清空当前书控件所有节点
∙m_Root=m_LeftTree.InsertItem("
动态切换视图"
);
//插入根节点
∙TV_INSERTSTRUCTTCItem;
//设屏蔽
∙TCItem.item.mask=TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
∙TCItem.hInsertAfter=TVI_LAST;
//在最后项之后
∙CStringstrTreeNodeName="
测试一"
;
∙pszText=strTreeNodeName.LockBuffer();
∙TCItem.hParent=m_Root;
∙TCItem.item.pszText=pszText;
∙TCItem.item.iImage=1;
∙TCItem.item.iSelectedImage=2;
∙HTREEITEMhCurrent=m_LeftTree.InsertItem(&
TCItem);
∙m_LeftTree.SetItemData(hCurrent,1);
∙strTreeNodeName="
测试二"
∙hCurrent=m_LeftTree.InsertItem(&
∙m_LeftTree.SetItemData(hCurrent,2);
∙m_LeftTree.Expand(m_Root,TVE_EXPAND);
//展开根节点
单链表"
∙TCItem.item.iSelected
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构
![提示](https://static.bdocx.com/images/bang_tan.gif)