Implementation (Part 1)
Lesson 5 of 9 in Coddy's Dijkstra's Algorithm - Graph Algorithms course.
First, reading weighted edges given as triples.
Challenge
EasyOur edges now come in triples. Let's get comfortable reading them.
Write a function named edgeWeight that takes the flat edges array (triples [u, v, w, ...], directed u -> v) and two vertices u and v, and returns the weight of the edge from u to v. If there is no such edge, return -1.
For example, edgeWeight([0,1,5, 0,2,3, 1,2,1], 0, 2) returns 3.
Try it yourself
#include <stdlib.h>
int edgeWeight(int* edges, int edges_size, int u, int v) {
// Write code here
return -1;
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Dijkstra's Algorithm - Graph Algorithms
2The Algorithm
How it works?Pseudo CodeImplementation (Part 1)Implementation (Part 2)