icp/oer/courses/c-advanced/sections/01-introduction/07-graphs/program.c

41 lines
993 B
C

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
// NOTE: These are the nodes
char *Names[5] =
{
"Mike",
"Bob",
"Anna",
"Emma",
"Nick"
};
// NOTE: These are the edges
// for now everyone can only like two other people
int Likes[5][2] =
{
{1,3}, // Mike likes Bob and Emma
{4,3},
{0,4},
{2,4},
{1,2}
};
// NOTE: if you wanted to be able to have as much edges as possible
// you could use a 2D-Array with the size of the number
// of Nodes. These Arrays are called adjacency-matrices.
// But these are inherently inefficient, when you have a graph with
// few connections.
// there are also other ways like storing the edges in the nodes
// in a list of pointers etc
// TODO: print out everyone, who likes one, which likes them back.
// if you want to you can try to prevent duplicates like A likes B
// and B likes A, but this is not required.
printf("%s and %s both like each other.\n", "Nobody", "No one");
}