1. Trang chủ
  2. » Tất cả

Đồ án cây tìm kiếm nhị phân và ứng dụng trong quản lý hồ sơ trong máy tính

23 46 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

Untitled BỘ GIÁO DỤC VÀ ĐÀO TẠO ĐẠI HỌC KINH TẾ TP HỒ CHÍ MINH (UEH) TRƯỜNG CÔNG NGHỆ VÀ THIẾT KẾ  ĐỒ ÁN MÔN HỌC ĐỀ TÀI CÂY TÌM KIẾM NHỊ PHÂN VÀ ỨNG DỤNG TRONG QUẢN LÝ HỒ SƠ TRONG MÁY TÍNH Học Phần[.]

lOMoARcPSD|18034504 BỘ GIÁO DỤC VÀ ĐÀO TẠO ĐẠI HỌC KINH TẾ TP HỒ CHÍ MINH (UEH) TRƯỜNG CƠNG NGHỆ VÀ THIẾT KẾ  ĐỒ ÁN MÔN HỌC ĐỀ TÀI CÂY TÌM KIẾM NHỊ PHÂN VÀ ỨNG DỤNG TRONG QUẢN LÝ HỒ SƠ TRONG MÁY TÍNH Học Phần: Cấu Trúc Dữ Liệu & Giải Thuật Danh Sách Nhóm: Nguyễn Nhựt Phong Đỗ Tạ Minh Quân Nguyễn Tôn Minh Qn Trần Xn Ngọc Chun Ngành: Khóa: K47 CƠNG NGHỆ PHẦN MỀM Giảng Viên: TS Đặng Ngọc Hoàng Thành Tp Hồ Chí Minh, Ngày 15 tháng 12 năm 2022 lOMoARcPSD|18034504 MỤC LỤC MỤC LỤC CHƯƠNG CÂY NHỊ PHÂN TÌM KIẾM 1.1 Các Khái Niệm Liên Quan 1.2 Cấu Trúc Cài Đặt Cây BST 1.3 Các Thuật Toán Trên Cây BST a) Thuật Toán Thêm nút vào BST b) Thuật Toán Thăm nút BST c) Thuật Tốn Tìm nút Min/Max d) Thuật Toán Xác định độ cao BST e) Thuật Tốn Tìm nút BST f) Thuật Tốn Xóa nút BST CHƯƠNG PHÂN TÍCH VÀ THIẾT KẾ LỚP .10 2.1 Phân Tích Bài Tốn Tìm Kiếm Hồ Sơ Bằng Cây BST 10 2.2 Sơ Đồ Lớp 10 2.3 Cài Đặt Lớp 10 CHƯƠNG THIẾT KẾ GIAO DIỆN 14 3.1 Giao Diện Menu Chính 14 3.2 Chi Tiết Chức Năng 14 CHƯƠNG THẢO LUẬN & ĐÁNH GIÁ 18 5.1 Các Kết Quả Nhận Được 18 5.2 Một Số Tồn Tại 19 5.3 Hướng Phát Triển 20 PHỤ LỤC 21 TÀI LIỆU THAM KHẢO .23 lOMoARcPSD|18034504 CHƯƠNG CÂY NHỊ PHÂN TÌM KIẾM 1.1 Các Khái Niệm Liên Quan Cây (Tree) dạng cấu trúc liệu bao gồm: đỉnh (Node) cạnh (Edge) Các đỉnh chứa thông tin kết nối cạnh Tập thứ tự cạnh tạo thành đường (Path) Đỉnh gọi gốc (Root) Các đỉnh lại gọi nút (Child) Đỉnh khơng có nút gọi (Leaf) Các đỉnh phân thành mức khác (level 0, level 1, v.v) Một mà đỉnh có khơng q hai nút con: nút trái (left) nút phải (right) gọi nhị phân (Binary tree) CÂY TÌM KIẾM NHỊ PHÂN (BST – Binary Search Tree): Giá trị tất nút bên trái giá trị nút gốc Tất (bao gồm bên trái phải) phải đảm bảo hai tính chất 1.2 Cấu Trúc Cài Đặt Cây BST Mỗi nút gồm có liệu (Data), nút trái (Left) nút phải (Right) lOMoARcPSD|18034504 Mỗi BST có nút gốc (Root) public class Node { public Node LeftNode { get; set; } public Node RightNode { get; set; } public int Data { get; set; } } public class BinarySearchTree { public Node Root { get; set; } //Tiếp tục cho hàm… } 1.3 Các Thuật Toán Trên Cây BST a) Thuật Toán Thêm nút vào BST public bool Insert(int value) { Node before = null, after = this.Root; while (after != null) { before = after; if (value < after.Data) after = after.LeftNode; else if (value > after.Data) after = after.RightNode; else return false; } Node newNode = new Node(); newNode.Data = value; if (this.Root == null) this.Root = newNode; else { if (value < before.Data) before.LeftNode = newNode; else before.RightNode = newNode; } return true; } b) Thuật Toán Thăm nút BST Duyệt theo trung thứ tự: lOMoARcPSD|18034504 public void TraverseInOrder(Node parent) { if (parent != null) { TraverseInOrder(parent.LeftNode); Console.Write(parent.Data + " "); TraverseInOrder(parent.RightNode); } } Duyệt theo tiền thứ tự: lOMoARcPSD|18034504 public void TraversePreOrder(Node parent) { if (parent != null) { Console.Write(parent.Data + " "); TraversePreOrder(parent.LeftNode); TraversePreOrder(parent.RightNode); } } Duyệt theo hậu thứ tự: lOMoARcPSD|18034504 public void TraversePostOrder(Node parent) { if (parent != null) { TraversePostOrder(parent.LeftNode); TraversePostOrder(parent.RightNode); Console.Write(parent.Data + " "); } } c) Thuật Tốn Tìm nút Min/Max Tìm nút Min: Cách 1: private int MinValueOfNode(Node node) { int minv = node.Data; while (node.LeftNode != null) { minv = node.LeftNode.Data; node = node.LeftNode; } return minv; } Cách 2: lOMoARcPSD|18034504 public int FindMin() { return MinValueOfNode(this.Root); } public int FindMin2() { Node current = Root; while (current.LeftNode != null) current = current.LeftNode; return current.Data; } Tìm nút Max: Cách 1: private int MaxValueOfNode(Node node) { int maxv = node.Data; while (node.RightNode != null) { maxv = node.RightNode.Data; node = node.RightNode; } return maxv; } Cách 2: public int FindMax() { return MaxValueOfNode(this.Root); } public int FindMax2() { Node current = Root; while (current.RightNode != null) current = current.RightNode; return current.Data; } d) Thuật Toán Xác định độ cao BST public int GetTreeDepth() { return this.GetTreeDepth(this.Root); } private int GetTreeDepth(Node parent) { return parent == null ? : Math.Max(GetTreeDepth(parent.LeftNode), GetTreeDepth(parent.RightNode)) + 1; } lOMoARcPSD|18034504 e) Thuật Toán Tìm nút BST public Node Find(int value) { return this.Find(value, this.Root); } private Node Find(int value, Node parent) { if (parent != null) { if (value == parent.Data) return parent; if (value < parent.Data) return Find(value, parent.LeftNode); else return Find(value, parent.RightNode); } return null; } f) Thuật Tốn Xóa nút BST public void Remove(int value) { this.Root = Remove(this.Root, value); } private Node Remove(Node parent, int key) { if (parent == null) return parent; if (key < parent.Data) parent.LeftNode = Remove(parent.LeftNode, key); else if (key > parent.Data) parent.RightNode = Remove(parent.RightNode, key); else { if (parent.LeftNode == null) return parent.RightNode; else if (parent.RightNode == null) return parent.LeftNode; parent.Data = MinValueOfNode(parent.RightNode); parent.RightNode = Remove(parent.RightNode, parent.Data); } return parent; } lOMoARcPSD|18034504 CHƯƠNG PHÂN TÍCH VÀ THIẾT KẾ LỚP 2.1 Phân Tích Bài Tốn Tìm Kiếm Hồ Sơ Bằng Cây BST Mơ tả thuật toán: Đầu tiên tạo class HoSo để lưu thuộc tính đối tượng hồ sơ như: Mã hồ sơ, Họ tên, Giới tính, Lương, Ngày làm (ngày thức làm việc) Tạo class Node để định nghĩa nút trái, nút phải liệu để hổ trợ cho class BinarySearchTree Tạo class BinarySearchTree để lưu thuộc tính đối tượng theo đề Trong class chứa phương thức chèn đối tượng vào cây, xếp theo thứ tự thời gian từ cũ đến in danh hồ sơ, tìm kiếm theo tên, tìm kiếm theo khoảng thời gian từ A đến B Yêu cầu: cần có kiến thức lớp, tìm kiếm nhị phân, biết áp dụng thuật tốn tìm kiếm BST không phần quan trọng khả làm winform để hoàn thành phần giao diện chương 2.2 Sơ Đồ Lớp 2.3 Cài Đặt Lớp 10 Downloaded by vu ga (vuchinhhp2@gmail.com) lOMoARcPSD|18034504 using using using using using using System; System.Collections.Generic; System.Globalization; System.Linq; System.Text; System.Threading.Tasks; namespace Do_an_CTDL { internal class Program { public class HoSo { public string MaHoSo { get; set; } public string Ten { get; set; } public string GioiTinh { get; set; } public int Luong { get; set; } public DateTime NgayLam { get; set; } } public class Node { public Node LeftNode { get; set; } public Node RightNode { get; set; } public HoSo Data { get; set; } } public class BinarySearchTree { public Node Root { get; set; } public bool Insert(HoSo value) { Node before = null, after = this.Root; while (after != null) { before = after; if (value.NgayLam after.Data.NgayLam) after = after.RightNode; else return false; } Node newNode = new Node(); newNode.Data = value; if (this.Root == null) this.Root = newNode; else { if (value.NgayLam

Ngày đăng: 23/02/2023, 21:57

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w