运行 ❯
获取您
的
网站
×
更改方向
更改主题,深色/浅色
前往 Spaces
Python
C
Java
vertexData = ['A', 'B', 'C', 'D'] adjacency_matrix = [ [0, 1, 1, 1], # Edges for A [1, 0, 1, 0], # Edges for B [1, 1, 0, 0], # Edges for C [1, 0, 0, 0] # Edges for D ] def print_adjacency_matrix(matrix): print("\nAdjacency Matrix:") for row in matrix: print(row) print('vertexData:',vertexData) print_adjacency_matrix(adjacency_matrix) #Python
#include <stdio.h> void printAdjacencyMatrix(int matrix[4][4], int size) { printf("\nAdjacency Matrix:\n"); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { printf("%d ", matrix[i][j]); } printf("\n"); } } int main() { char vertexData[4] = {'A', 'B', 'C', 'D'}; int adjacencyMatrix[4][4] = { {0, 1, 1, 1}, // Edges for A {1, 0, 1, 0}, // Edges for B {1, 1, 0, 0}, // Edges for C {1, 0, 0, 0} // Edges for D }; printf("vertexData: "); for (int i = 0; i < 4; i++) { printf("%c ", vertexData[i]); } printf("\n"); printAdjacencyMatrix(adjacencyMatrix, 4); return 0; } //C
public class Main { public static void main(String[] args) { String[] vertexData = {"A", "B", "C", "D"}; int[][] adjacencyMatrix = { {0, 1, 1, 1}, // Edges for A {1, 0, 1, 0}, // Edges for B {1, 1, 0, 0}, // Edges for C {1, 0, 0, 0} // Edges for D }; System.out.print("vertexData: "); for (String vertex : vertexData) { System.out.print(vertex + " "); } System.out.println(); System.out.println(); printAdjacencyMatrix(adjacencyMatrix); } public static void printAdjacencyMatrix(int[][] matrix) { System.out.println("Adjacency Matrix:"); for (int[] row : matrix) { for (int value : row) { System.out.print(value + " "); } System.out.println(); } } } //Java
Python 结果
C 结果
Java 结果
vertexData: ['A', 'B', 'C', 'D']
邻接矩阵
[0, 1, 1, 1]
[1, 0, 1, 0]
[1, 1, 0, 0]
[1, 0, 0, 0]
vertexData: A B C D
邻接矩阵
0 1 1 1
1 0 1 0
1 1 0 0
1 0 0 0
vertexData: A B C D
邻接矩阵
0 1 1 1
1 0 1 0
1 1 0 0
1 0 0 0