{"id":25841939,"url":"https://github.com/courseworks/ap1401-2-hw5","last_synced_at":"2025-06-30T05:04:02.952Z","repository":{"id":166771901,"uuid":"640382166","full_name":"courseworks/AP1401-2-HW5","owner":"courseworks","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-18T09:00:00.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T05:32:51.090Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/courseworks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-13T22:38:42.000Z","updated_at":"2024-04-30T02:59:13.000Z","dependencies_parsed_at":"2023-07-29T19:46:06.330Z","dependency_job_id":null,"html_url":"https://github.com/courseworks/AP1401-2-HW5","commit_stats":null,"previous_names":["courseworks/ap1401-2-hw5"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/courseworks/AP1401-2-HW5","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1401-2-HW5","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1401-2-HW5/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1401-2-HW5/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1401-2-HW5/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/courseworks","download_url":"https://codeload.github.com/courseworks/AP1401-2-HW5/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1401-2-HW5/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262714507,"owners_count":23352463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-01T05:32:51.358Z","updated_at":"2025-06-30T05:04:02.895Z","avatar_url":"https://github.com/courseworks.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Advanced Programming - HW5\n\u003cp  align=\"center\"\u003e \u003cb\u003eHomework 5 - Spring 2023 Semester \u003cbr\u003e Deadline: Wednesday khordad 3st - 11:59 pm\u003c/b\u003e \u003c/p\u003e\n\n## Outline\nA graph is a non-linear data structure. A graph can be defined as a collection of Nodes which are also called *vertices* and *edges* that connect two or more vertices.\n\nIn this homework we want to implement graph data structure. We use the adjacency list for the linked representation of the graph. The adjacency list representation maintains each node of the graph and a link to the nodes that are adjacent to this node. When we traverse all the adjacent nodes, we set the next pointer to null at the end of the list.\n![](./resources/graph.png)\n\n## Graph class\n```cpp\ntemplate\u003ctypename T\u003e\nclass Graph\n{\npublic:\n    // TODO: constructors and methods\nprivate:\n    class Node\n    {\n    public:\n        T value{};\n        Node* next{};\n        //TODO: constructors and methods\n    };\n    std::vector\u003cNode*\u003e head;\n};\n```\n### Functions\n- ` void addVertex(const T\u0026 v)`: get T and add to graph.\n- `void addEdge(const T\u0026 v1, const T\u0026 v2, int a,  std::function\u003cbool(T, T)\u003e func)`: get two nodes and weight to add edge from v1 to v2. Use func to search in the graph and find(set default function to it).If edge exist, replace it with new weight.\n- `int getNumEdges()`: The number of edges in the graph.\n- `vector\u003cT\u003e getNeighbors(T vertex, std::function\u003cbool(T, T)\u003e func)`: Get the list of neighbors of a vertex(set default function to it).\n- `bool isConnected(T source, T destination, std::function\u003cbool(T, T)\u003e func)`: Check if two vertices are connected(set default function to it).\n- `vector\u003cT\u003e findShortestPath(T source, T destination, std::function\u003cbool(T, T)\u003e func)`: Find the shortest path between two vertices(set default function to it).\n- `int getNumConnectedComponents()`:Get the number of connected components in the graph.\n- `void bfs(int vertex, vector\u003cbool\u003e\u0026 visited)`: implement Breadth-first search (BFS)\n- `vector\u003cT\u003e topologicalSort()`: [_link_](https://en.wikipedia.org/wiki/Topological_sorting#:~:text=In%20computer%20science%2C%20a%20topological,before%20v%20in%20the%20ordering.)\n\n## part 2\nImplement a binary search tree that can store int data that can be compared using the less-than operator. The program should also be able to perform the following operations on the tree:\n![](./resources/bin.jpeg)\n- Insert a new node into the tree\n- Delete a node from the tree\n- Find a node in the tree\n- Print the contents of the tree in sorted order\n\n```cpp\nstruct Node {\n    int value;\n    Node* left;\n    Node* right;\n\n    Node(int value) {\n        this-\u003evalue = value;\n        left = nullptr;\n        right = nullptr;\n    }\n};\n\nNode* insert(Node* root, int value) {\n}\n\nvoid deleteNode(Node* root, int value) {\n}\n\nNode* find(Node* root, int value) {\n}\n\nvoid printInOrder(Node* root) {\n}\n```\n\u003cbr/\u003e\n\u003cp  align=\"center\"\u003e \u003cb\u003eGOOD LUCK\u003c/b\u003e \u003c/p\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcourseworks%2Fap1401-2-hw5","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcourseworks%2Fap1401-2-hw5","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcourseworks%2Fap1401-2-hw5/lists"}