TAILIEUCHUNG - Faculty of Computer Science and Engineering Department of Computer Science - LAB SESSION 3 RECURSION

Faculty of Computer Science and Engineering Department of Computer Science LAB SESSION 3 RECURSION on BINARY TREE 1. OBJECTIVE The objectives of Lab 3 are (1) to introduce an implementation of binary tree in C++ and (2) to practice recursion algorithms to manipulate a tree. 2. FILE-LEVEL SEPARATION of INTERFACE and IMPLEMENTATION Class interface and implementation In Lab 2, we have learnt about the concept of separation between the interface and the implementation of a class. In practice, the separation is implemented as the file-level, . we store the interface and the implementation in different files, whose extensions are respectively. | Faculty of Computer Science and Engineering Department of Computer Science LAB SESSION 3 RECURSION on BINARY TREE 1. OBJECTIVE The objectives of Lab 3 are 1 to introduce an implementation of binary tree in C and 2 to practice recursion algorithms to manipulate a tree. 2. FILE-LEVEL SEPARATION of INTERFACE and IMPLEMENTATION Class interface and implementation In Lab 2 we have learnt about the concept of separation between the interface and the implementation of a class. In practice the separation is implemented as the file-level . we store the interface and the implementation in different files whose extensions are respectively .h and .cpp. Listing 1 and Listing 2 illustrate the contents of two files so-called and corresponding to the interface and implementation of a binary tree. Please notice the red-colored statement include in the file . It is very important to make the understand what are declared in . Please refer to manuals of the C language if you truly want to know the real meaning of the directive include. this is the content of struct Node int data Node left right class Tree public Tree Tree protected Node root void destroy Node Listing 1 this is the content of include Tree Tree root NULL 1 3 Faculty of Computer Science and Engineering Department of Computer Science _ II-------------------------------------- Tree Tree destroy root root NULL II-------------------------------------- Tree destroy Node root if root NULL destroy root- left destroy root- right delete root Listing 2 3. RECURSION in BINARY TREE Recursion is an unavoidable technique to handle many operations in a binary tree. In Listing 2 an example is given to illustrate how to use recursion to collect garbage when a tree is deleted. Basically to construct an algorithm for a tree binary we should do the following steps - Process the stop condition think the simplest case . an empty tree and what we should do in this case.

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.