Menu
Coddy logo textTech

Implementation (Part 1)

Lesson 5 of 9 in Coddy's Dijkstra's Algorithm - Graph Algorithms course.

First, reading weighted edges given as triples.

challenge icon

Challenge

Easy

Our 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;
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Dijkstra's Algorithm - Graph Algorithms