Recently, because in the process of using VB, I found some data structures, although it is not as convenient to C, but sum up, it can still be done, although not very habit. Take you.
In order to facilitate the understanding of the role of the array, we introduce the concept of data items and pointer items, store the value of each element in the array in the data item, and store the position in the array in the pointer item, and the two corresponds. The upper limit of the pointer points to the position of the first element of the array, the lower limit pointing to the position of the last element. The elements in the array are continuous linear node sequences in memory. This linear data structure is the most widely used and simplest data structure. Custom Data Types (Type Statement) can include elements of multiple inter-associated data types, VB definition declaration a custom data type must be done at the module layer. Declare a custom data type and define one type of variable. 1. Custom data type named QUEUE declares a fixed size array: Type Queuedata As INTEGER 'Used as Data Nobs NEXT AS INTEGER' Used as Net Item
End typeconst max = 10dim a (10) As queue set A (i) an element in an array, the pointer of the element pointing to the array A (10) i 1 element, which is subscribed to I, the value of the pointer is i. It should be noted that the data structure is different from the data type, which is also different from the object (variable) of the data type declaration. The data structure not only describes the data objects of the data type, but also describes the various operations between the data objects. In order to clarify the role of the custom data type, we specify the value of the variable DATA storage element (as a data field), the variable next stores the pointer to the elements of the element. By using custom data type Queue declares array a (10) and makes special provisions for variable next, we can find that we can store a continuous linear distribution of data in memory in memory in non-linear discontinuous address space, but not Impact us for linear operations. As such a structure that utilizes a pointer links the structure of each element is referred to as a linked list, the arrays defined by similar example 1 can be used as a linked list. Use Queue to initial A (10) to a one-way link table: for i = 0 to 9 a (i) .Next = i 1 'i 1 is the first element pointer A (i) .DATA = 10 * RndNext I 2. Stack and queue stacks are commonly used data structures. In the Visual Basic programming, the stack can be used to achieve recursive effects; or resource recycling due to deletion of array and linked lists, avoiding an embarrassing situation between resource idle, array or linked table length. Stacks can be stored in one-dimensional array or linked list. Using an array to achieve both easy and convenient, at this time, point to the array node with a pointer variable TOP1, each time there is an element into the stack top pointer TOP1 = TOP1 1, A (TOP1) .DATA = 10 * RND, each time there is an element Find TOP1 = TOP1-1, B = A (TOP1) .DATA. When top1 = 0 stack empty, TOP1 is equal to the upper limit of the array. Unlike the stack, the queue is the advanced data structure, and the queue can also be stored in one-dimensional array or linked list. In the team, two pointer variables TOP1, BOTTOM, and finally enter the team's pointer to the head pointer TOP1, the pointer of the most advanced team elements in the team is equal to the tail pointer bottom, when top1 = bottom When the team is empty, the initial condition is top1 = bottom = 0, when top1 1 = bottom (array) or A (TOP1) .Next = Bottom is full. TOP1 = TOP1 1 (array) or top1 = a (TOP1) .Next (Link) when there is an element to come out when the element is out of the team, or bottom = a (bottom) .next ). Using fixed-size arrays will always encounter a stack full or team full, we can use dynamic arrays to avoid that the dynamic array is an important feature of Visual Basic flexibility and convenience, which can effectively manage memory. In Example 3, the operation of inserting a node in the linked list is inserted by introducing variables LINSHI. The operation of deleting a node in the linked list is similar. Example: Queue's entry and queue operations, using the above-defined loop chain list and assume that it has been initialized in Example 2.