forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdge.java
More file actions
33 lines (29 loc) · 858 Bytes
/
Edge.java
File metadata and controls
33 lines (29 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.thealgorithms.graph;
/** Represents an edge in an undirected weighted graph. */
public class Edge implements Comparable<Edge> {
public final int source;
public final int destination;
public final int weight;
/**
* Constructs an edge with given source, destination, and weight.
*
* @param source the source vertex
* @param destination the destination vertex
* @param weight the weight of the edge
*/
public Edge(final int source, final int destination, final int weight) {
this.source = source;
this.destination = destination;
this.weight = weight;
}
/**
* Compares edges based on their weight.
*
* @param other the edge to compare with
* @return comparison result
*/
@Override
public int compareTo(final Edge other) {
return Integer.compare(this.weight, other.weight);
}
}