데이터 구조 (10) - 그림 의 인접 표 저장

7023 단어 데이터 구조
//////////////////////////////////////////////////////////

//       

//////////////////////////////////////////////////////////

#include <iostream>

#include <stdlib.h>

using namespace std;

//        

#define MaxVertexNum 100

enum GraphType{DG, UG, DN, UN};//   ,   ,    ,    



typedef struct node

{

    int AdjV; //    

    struct node *Next; //            

    //           ,         Weight

}EdgeNode; //    



typedef char VertexType; //       

typedef struct Vnode

{

    VertexType Vertex; //   

    EdgeNode *FirstEdge;  //     

}VertexNode;



typedef VertexNode AdjList[MaxVertexNum]; //AdjList      



typedef struct

{

    AdjList adjlist; //   

    int n, e; //      

    enum GraphType GType; //    

}ALGraph; //ALGraph             



void CreateALGraph(ALGraph *G)

{

    int i, j, k;

    EdgeNode *edge;

    G->GType = DG; //   

    cout << "         (     :   ,  ):
" << endl; cin >> G->n >> G->e; // cout << " ( : <CR>):
"; for (i = 0; i < G->n; i++) {// n cin >> &G->adjlist[i].Vertex; // G->adjlist[i].FirstEdge = NULL; // } cout << " ( :i,j<CR>):
"; for (k = 0; k < G->e; k++) // { cin >> i >> j; edge = new EdgeNode; edge->AdjV = j; edge->Next = G->adjlist[i].FirstEdge; // edge vi G->adjlist[i].FirstEdge = edge; // , , <vj, vi> } } void Print(ALGraph *G) { for (int i = 0; i < G->n; i++) { EdgeNode *p = G->adjlist[i].FirstEdge; cout << G->adjlist[i].Vertex << " "; while (p != NULL) { cout << p->AdjV << " "; p = p->Next; } cout << endl; } } int main() { ALGraph *G = new ALGraph; CreateALGraph(G); Print(G); system("pause"); return 0; }

좋은 웹페이지 즐겨찾기