• 大小: 965B
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2021-01-07
  • 语言: Python
  • 标签: 深度搜索  python  

资源简介

对图的类型没有限制, 邻接矩阵表示,实例认证 包含图和相关代码,输出遍历的顺序

资源截图

代码片段和文件信息

# -*- coding: utf-8 -*-
“““
Created on Sat Oct 28 11:00:21 2017

@author: Administrator
“““
import numpy as np

def read(path):
    file = open(path)
    lines = file.readlines()
    n = int(lines[0])
    m = 0
    nums = np.zeros((n n))
    for i in range(0 n):
        for j in range(0 n):
            nums[i][j] = 0
    # print(nums)
    for line in lines[1:]:
        st = line.strip(‘\n‘)
        s = st.split(‘,‘)
        # print(type(s)s)
    # 这里需要注意逗号的形式,是英文还是中文!!!
        s = [float(x) for x in s]
        a b w = s
        # print(a b w)
        nums = matrix(a b w nums)
        # print(nums)
        m += 1
    print(‘nodes:‘ n)
    print(‘arcs:‘ m)
    file.close()
    return nums m n

def matrix(a b w nums):
    count = len(nums)

评论

共有 条评论