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

📄 shortpth.cpp

📁 图论:最短路径算法实现 Graph.gph GraphBFS.h GraphM.h GraphOpr.h Queue.h sample.gph ShortPth.cpp ShortPt
💻 CPP
字号:
#include <assert.h>
#include <iostream.h>
#include <stdlib.h>

#include "graphopr.h"
#include "graphbfs.h"


void main()
{
  Graph* G;
  FILE *fp;
  char *filename;

  filename = new char[255];

  cout << "Filename:" << endl;
  cin >> filename;

  if ((fp = fopen(filename, "rt")) == NULL)
  {
    cout << "Unable to open file |" << filename << "|" << endl;
	cout << "To know file format, View sample.gph" << endl;
    exit(-1);
  }

  G = readGraph(fp);

  if (G == NULL)
  {
    cout << "Unable to create graph" << endl;
	cout << "To know file format, View sample.gph" << endl;
    exit(-1);
  }
  
  printGraph(G);

  Queue<int>* Q = new Queue<int>(G->n());

  int* path = new int[G->n()];
  
  int c;

  cout << "1. Continue test ShortestPath" << endl;
  cout << "0. Exit" << endl;
  cout << "----------------------------------------" << endl;
  cout << "Choice:" << endl;

  cin >> c;

  int s, d;

  while (c != 0)
  {
  for (int i = 0; i < G->n(); i++)
	path[i] = UNREACHABLE;

  cout << "Input source node(0 - " << G->n() - 1 << "):" << endl;

  cin >> s;

  while (s < 0 || s >= G->n())
	cin >> s;
  
  cout << "Input destination node(0 - " << G->n() - 1 << "):" << endl;

  cin >> d;

  while (d < 0 || d >= G->n())
	cin >> d;

  shortestPath(G, s, d, Q, path);
  cout << endl;

  cout << "1. Continue test ShortestPath" << endl;
  cout << "0. Exit" << endl;
  cout << "----------------------------------------" << endl;
  cout << "Choice:" << endl;

  cin >> c;

  }
 
}

⌨️ 快捷键说明

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