{"id":25841963,"url":"https://github.com/courseworks/ap1400-2-hw3","last_synced_at":"2026-06-12T15:31:07.629Z","repository":{"id":119844532,"uuid":"473232688","full_name":"courseworks/AP1400-2-HW3","owner":"courseworks","description":"Advanced Programming - HW3","archived":false,"fork":false,"pushed_at":"2022-03-23T14:52:06.000Z","size":6,"stargazers_count":17,"open_issues_count":0,"forks_count":29,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-28T02:57:55.198Z","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-03-23T14:49:13.000Z","updated_at":"2025-09-29T17:53:14.000Z","dependencies_parsed_at":"2023-06-03T08:30:46.222Z","dependency_job_id":null,"html_url":"https://github.com/courseworks/AP1400-2-HW3","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/courseworks/AP1400-2-HW3","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1400-2-HW3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1400-2-HW3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1400-2-HW3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1400-2-HW3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/courseworks","download_url":"https://codeload.github.com/courseworks/AP1400-2-HW3/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP1400-2-HW3/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34251774,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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:57.157Z","updated_at":"2026-06-12T15:31:07.623Z","avatar_url":"https://github.com/courseworks.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Advanced Programming - HW3\r\n\u003cp  align=\"center\"\u003e \u003cb\u003eHomework 3 - Spring 2022 Semester \u003cbr\u003e Deadline: Sunday Farvardin 14st - 11:59 pm\u003c/b\u003e \u003c/p\u003e\r\n\r\n## Outline\r\n\r\nIn this homework we are going to implement a *Binary Search Tree (BST)*. A *binary tree* is a tree graph in which nodes can only have upto 2 children. A *Binary Search Tree* is a binary tree in which the right child of each node have a greater value than the left one.\r\n\r\nWe are going to implement 2 classes one of them is called `Node` which represents each node in the graph, and the other one is `BST` which is responsible to conncet nodes in a  way to construct a binary search tree. Since the `Node` class is a direct property of the `BST` class; It should be defined inside the BST class.\r\n\r\n**note.** You are only allowed  to alter `bst.cpp/h` and only the debug section of `main.cpp`. \r\n\r\n\u003c/br\u003e\r\n\r\n# Node Class\r\nUse the code fraction bellow to implement this class. **note.** you may need to add some keywords to these functions if necessary. other than these keywords you are not allowed to change the functions or add new member functions to this class **unless otherwise specified in the following**.\r\n\r\n```cpp\r\nclass Node\r\n{\r\npublic:\r\n\tNode(int value, Node* left, Node* right);\r\n\tNode();\r\n\tNode(const Node\u0026 node);\r\n\r\n\tint value;\r\n\tNode* left;\r\n\tNode* right;\r\n};\r\n```\r\n\r\n---\r\n\r\nEach node has a integer value and can point to its children using left and right pointers. If one or more children does not exist assign `nullptr` to them.\r\n\r\n- **std::cout**\r\nImplement the `\u003c\u003c` operator so that you would be able to use `std::cout` to print a node in one line and in a beautiful way, the output should contain the node's address, the node's value, node's left child address, and node's right child address.\r\n\r\n- **inequality with an int**\r\nimplement proper functions so that every possible inequality between a node and an int can be made i.e.\r\n\r\n\t```cpp\r\n\tnode \u003e 4\tnode \u003e= 5\tnode \u003c 6\tnode \u003c= 5\tnode == 3\r\n\t5 \u003c node\t6 \u003c= node\t2 \u003e node\t2 \u003e= node\t3 == node\r\n\t```\r\n\r\n\r\n\u003c/br\u003e\r\n\r\n# BST Class\r\nUse the code fraction bellow to implement this class. **note.** you may need to add some keywords to these functions if necessary. other than these keywords you are not allowed to change the functions or add new member functions to this class **unless otherwise specified in the following**.\r\n\r\n```cpp\r\nclass BST\r\n{\r\npublic:\r\n    Node*\u0026 get_root();\r\n    void bfs(std::function\u003cvoid(Node*\u0026 node)\u003e func);\r\n    size_t length();\r\n    bool add_node(int value);\r\n    Node** find_node(int value);\r\n    Node** find_parrent(int value);\r\n    Node** find_successor(int value);\r\n    bool delete_node(int value);\r\n\r\nprivate:\r\n    Node* root;\r\n};\r\n```\r\n\r\n---\r\nThis class is responsible to construct a BST graph by connceting the nodes in a proper manner. `root` is the only member variable of this class which points to the first node of the binary search tree.\r\n\r\n- **get_root**\r\nreturnts the private member variable `root`.\r\n\r\n- **bfs**\r\n*Breadth-first search (BFS)* is an algorithm for searching a tree by iterating through each and every node; Implement this algorithm! \u003c/br\u003e This function has a input of `std::function`, this type behaves like a pointer to function and can wrapp any callable objects in c++ like ordinary or lambda functions. you are going to use lambda functions in this homework so feel free to search and learn about them. \u003c/br\u003e The user should be able to use this argument and apply any functions on the nodes of the tree i.e. call the object `func` on every node found by BFS algorithm.\r\n\r\n- **length**\r\nreturnts the number of nodes exist in bst.\r\n\r\n- **add_node**\r\nadds a new node to BST in the proper place. **note.** the user should not be able to add a value that already exists in the tree.\r\n\r\n- **find_node**\r\nfinds the node in tree with the specified value and returns a pointer to the pointer of the node. \u003c/br\u003e **note.** do not use bfs algorithm to find the nod, instead use the property of binary search trees: *that is why we use them in the first place*.\r\n\r\n- **find_parrent**\r\nfinds the parrent node of a node with specified value and returns a pointer to the pointer of that parrent. \u003c/br\u003e **note.** do not use bfs algorithm to find the node.\r\n\r\n- **find_successor**\r\nfinds a successor of a node with specified value.\r\n\r\n- **delete_node**\r\ndeletes a node with the specified value. if there is no such node with that value return false.\r\n\r\n- **std::cout**\r\nImplement the `\u003c\u003c` operator so that you would be able to use `std::cout` to print a BST in a beautiful way. to do so print each node of the BST. You'll receive extra points if you manage to generate a output exactly as bellow (stars are part of the output).\r\n\r\n\t```cpp\r\n\t********************************************************************************\r\n\t0x188dee70       =\u003e value:25        left:0x188dedd0      right:0x188dedf0      \r\n\t0x188dedd0       =\u003e value:10        left:0x188dee30      right:0x188ded90      \r\n\t0x188dedf0       =\u003e value:50        left:0               right:0x188dee50      \r\n\t0x188dee30       =\u003e value:7         left:0               right:0               \r\n\t0x188ded90       =\u003e value:15        left:0               right:0               \r\n\t0x188dee50       =\u003e value:53        left:0               right:0               \r\n\tbinary search tree size: 6\r\n\t******************************************************************************** \r\n\t```\r\n\r\n- **operator++**\r\nImplement both `++` operators so that they would add 1 to each and every nodes in the tree. \u003cbr/\u003e do not forget the difference between `bst++` and `++bst`.\r\n\r\n- **destructor**\r\nAs you now, when dealing with dynamic objects in a class creating destructors are a neccessaty. Fortunately for you I will burden the implementation of your destructor myself, so implement the bellow code as your class destructor.\r\n\r\n\t```cpp\r\n\tBST::~BST()\r\n\t{\r\n\t\tstd::vector\u003cNode*\u003e nodes;\r\n\t\tbfs([\u0026nodes](BST::Node*\u0026 node){nodes.push_back(node);});\r\n\t\tfor(auto\u0026 node: nodes)\r\n\t\t\tdelete node;\r\n\t}\r\n\t```\r\n\r\n- **Constructors**\r\nImplement 3 constructors for the class: **I)** defualt constructor. **II)** copy constructor. **III)** move constructor.\r\n\r\n- **operator=**\r\nImplement both versions of `operator=` (copy and move versions).\r\n\r\n\u003c/br\u003e \r\n \r\n# Challenge\r\n- If you reached this section congratulations, there is only one part left and its an easy one. Make arrangements so you can add any number of nodes using the constructor. meaning the bellow code should work.\r\n\r\n\r\n\t```cpp\r\n\tBST bst1{5, 1, 10, 2, 8, 50, 4, 60};\r\n    BST bst2{3, 2, 100, 20, 8, 50, 4, 60, 44, 23};\r\n\t```\r\n\u003c/br\u003e\r\n\r\n# Finally\r\nAs mentioned before, do not alter other files already populated except otherwise indicated. In case you want to test your code you may use the `debug` section of the `main.cpp`.\r\n\r\n```cpp\r\nif (true) // make false to run unit tests  \r\n{ \r\n\t// debug section \r\n}  \r\nelse  \r\n{  \r\n\t::testing::InitGoogleTest(\u0026argc, argv);  \r\n\tstd::cout \u003c\u003c \"RUNNING TESTS ...\" \u003c\u003c std::endl;  \r\n\tint ret{RUN_ALL_TESTS()};  \r\n\tif (!ret)  \r\n\t\tstd::cout \u003c\u003c \"\u003c\u003c\u003cSUCCESS\u003e\u003e\u003e\" \u003c\u003c std::endl;  \r\n\telse  \r\n\t  std::cout \u003c\u003c \"FAILED\" \u003c\u003c std::endl;  \r\n}  \r\nreturn 0;\r\n```\r\n\u003cbr/\u003e\r\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%2Fap1400-2-hw3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcourseworks%2Fap1400-2-hw3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcourseworks%2Fap1400-2-hw3/lists"}