Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Phương pháp này trả về False nếu mảng là các yếu tố và thật khác. Các tài sản hiện tại được thực hiện như một thuộc tính chỉ đọc, vì mục đích duy nhất của nó là để trả về các yếu tố hiện tại của mảng:Chỉ đọc tài sản hiện tại () Khi đối tượng _ thực hiệnMột mô hình đồ thị Đạo của chuỗi chương trình giảng dạy Khoa học máy tính. | 74 BASIC SORTING ALGORITHMS The only tricky part of this class definition resides within the Insert definition. It s entirely possible that user code could attempt to insert an item into the array when the upper bound of the array has been reached. There are two possible ways to handle this situation. One is to alert the user that the end of the array has been reached and not perform the insertion. The other solution is to make the array act like an ArrayList and provide more capacity in the array by using the Redim Preserve statement. That s the choice used here. You should also note that the showArray method only accesses those array elements that have data in them. The easiest way to write this method is to loop through the upper bound of the array. This would be a bad decision because there might be array elements where no data are stored which leaves zeroes or empty strings to be displayed. Let s see how this class works by writing a simple program to load the array with 50 values though the original upper bound is only through 9 and display the values Sub Main Dim theArray As New CArray 9 Dim index As Integer For index 0 To 49 theArray.Insert index Next theArray.showArray Console.Read End Sub The output looks like this Before leaving the CArray class to begin the examination of sorting and searching algorithms let s discuss how we re going to actually store data in a CArray class object. To demonstrate most effectively how the different sorting algorithms work the data in the array need to be in a random order. This is best achieved by using a random number generator to assign each array element to the array. Sorting Algorithms 75 The easiest way to generate random numbers is to use the Rnd function. This function returns a random number less than or equal to zero. To generate a random number within a particular range say from 1 to 100 use the following formula 100 Rnd 1 This formula only guarantees that the number will fall in the range of 1 to 100 not that