grkruskm.cpp

来自「经典c++程序的实现」· C++ 代码 · 共 46 行

CPP
46
字号
// Prim's MST algorithm -- v^2 version
#include <stdio.h>
#include <iostream.h>
#include <assert.h>

#define ROOT -1

#include "book.h"

#include "grmat.h"

typedef Edge ELEM;

#include "uf.h"

#include "minheap.h"

void AddEdgetoMST(int v1, int v2) {
  cout << "Add edge " << v1 << " to " << v2 << "\n";
}

#include "grkrusk.c"

main(int argc, char** argv) {
  Graph G;
  FILE *fid;
  int i, j;

  if (argc != 2) {
    cout << "Usage: grkruskm <file>\n";
    exit(-1);
  }

  if ((fid = fopen(argv[1], "rt")) == NULL) {
    cout << "Unable to open file |" << argv[1] << "|\n";
    exit(-1);
  }

  if (!createGraph(G, fid)) {
    cout << "Unable to create graph\n";
    exit(-1);
  }

  Kruskel(G);
}

⌨️ 快捷键说明

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