Run ❯
Get your
own
website
×
Change Orientation
Change Theme, Dark/Light
Go to 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
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 result:
C result:
Java result:
vertexData: ['A', 'B', 'C', 'D']
Adjacency Matrix:
[0, 1, 1, 1]
[1, 0, 1, 0]
[1, 1, 0, 0]
[1, 0, 0, 0]
vertexData: A B C D
Adjacency Matrix:
0 1 1 1
1 0 1 0
1 1 0 0
1 0 0 0
vertexData: A B C D
Adjacency Matrix:
0 1 1 1
1 0 1 0
1 1 0 0
1 0 0 0