const courses = createGraph({
nodes: [
{ id: 'CS101', data: { name: 'Intro to CS' } },
{ id: 'CS201', data: { name: 'Data Structures' } },
{ id: 'CS301', data: { name: 'Algorithms' } },
{ id: 'CS401', data: { name: 'Advanced Algorithms' } },
],
edges: [
{ id: '1', sourceId: 'CS101', targetId: 'CS201' },
{ id: '2', sourceId: 'CS201', targetId: 'CS301' },
{ id: '3', sourceId: 'CS301', targetId: 'CS401' },
],
});
const order = getTopologicalSort(courses);
if (order) {
console.log('Take courses in this order:');
order.forEach((course, i) => {
console.log(`${i + 1}. ${course.id}: ${course.data.name}`);
});
}