tailieunhanh - DATA STRUCTURES AND ALGORITHMS USING VISUAL BASIC.NET phần 10

1. 2. 3. 4. 5. 6. CS1 CS2 hội Ngôn ngữ Cấu trúc dữ liệu hệ điều hành thuật toánCác thuật toán cơ bản để phân loại topo là rất đơn giản: 1. 2. 3. 4. Tìm một đỉnh mà không có kế. Thêm đỉnh một danh sách các đỉnh. Hủy bỏ các đỉnh đồ thị. Lặp lại bước 1 cho đến khi tất cả các đỉnh được loại bỏ. | 368 ADVANCED ALGORITHMS The next class to examine is the TreeList class. This class is used to store the list of nodes that are placed into the binary tree using a linked list as the storage technique. Here s the code Public Class TreeList Private count As Integer 0 Private first As Node Public Sub addLetter ByVal Letter As String Dim hTemp As New HuffmanTree Letter Dim eTemp As New Node hTemp If first Is Nothing Then first eTemp Else first first eTemp End If count 1 End Sub Public Sub sortTree Dim otherList As New TreeList Dim aTemp As HuffmanTree While Not Is Nothing aTemp aTemp End While End Sub Public Sub mergeTree If Not first Is Nothing Then If Not Is Nothing Then Dim aTemp As HuffmanTree removeTree Dim bTemp As HuffmanTree removeTree Dim sumTemp As New HuffmanTree aTemp bTemp Greedy Algorithms 369 insertTree sumTemp End If End If End Sub Public Function removeTree As HuffmanTree If Not first Is Nothing Then Dim hTemp As HuffmanTree hTemp first count - 1 Return hTemp End If Return Nothing End Function Public Sub insertTree ByVal hTemp As HuffmanTree Dim eTemp As New Node hTemp If first Is Nothing Then first eTemp Else Dim p As Node first While Not Is Nothing If And _ Then Exit While End If p End While eTemp End If count 1 End Sub Public Function length As Integer Return count End Function End Class 370 ADVANCED ALGORITHMS This class makes use of the HuffmanTree class so let s view that code now Public Class HuffmanTree Private leftchild As HuffmanTree Private rightChild As HuffmanTree Private Letter As String Private freq As Integer Public Sub New ByVal Letter As String Letter End Sub Public Sub setLeftChild ByVal newChild As HuffmanTree leftChild .