C # knowledge point summary series: C # Data Structure

Source: Internet
Author: User

A finite sequence of data elements with the same characteristics in a Linear table (Linear List. Sequence storage structure of a linear table-sequence storage structure of a linear table refers to storing data elements of a linear table in sequence using a sequential storage space with an address. This storage method is like a bank before the reform. It needs to get money in queue before the business window. It can be seen that logically Adjacent Elements in a sequence table are physically adjacent. Sequence Table features 1. fixed storage capacity the sequence table elements require a whole block of memory space. Therefore, once the sequence table capacity is determined, it cannot be changed. 2. Fast access speed it is very simple and fast to access data elements in a sequence table using indexes. As shown in Figure 2.3, assume that the first element in the sequence table is Loc and the storage space occupied by each data element is n, then we can quickly calculate the storage address of the I-th element as: Loc + (I-1) * n. The most direct representation of the sequential storage structure of an array linear table in C # Is an array. In C #, arrays are the most basic and fastest collection type. Arrays are reference types. The memory space required to save them will be allocated on the managed stack. Once the array is created, all the elements will be initialized as their default values. Int [] arrInt = newint [5]; arrInt [2] = 5; arrInt [4] = 3; the Code above declares an array of int values, and initialize the length to 5, and assign values to the 3rd and 5th elements respectively. When the array element is of the value type, the array object stores the value type object itself. When the element is of reference type, the array object stores the object reference (pointer ). Control [] arrCtrl = new Control [5]; arrCtrl [0] = new Button (); arrCtrl [3] = new Label (); the code above declares an array of Control reference types, initializes its length to 5, and assigns values to the 1st and 4th elements respectively. The two values are Button and Label objects respectively. Although they all inherit from the Control class, they are different classes and their sizes are different. C # And Data Structure -- ArrayList 2.2.3 ArrayList C # dynamically changes the array size. ArrayList is also called a dynamic array. Its storage space can be dynamically changed. It also has the function of adding and deleting elements. The Insert (int index, object value) method is used to Insert an element to a specified index. To ensure that each element in the sequence table is physically adjacent to each other, all elements after the insertion point are moved one by one. The RemoveAt (int index) method is used to delete the elements of a specified index. After a specified element is deleted, all elements after the deleted vertex are moved one by one. Binary Tree storage structure binary tree storage can be divided into two types: sequential Storage Structure and chain storage structure. 1. The sequential storage structure stores top-down and left-right serial numbers of a full Binary Tree in an array sequentially. The result shown in Figure 6.8 (a) is displayed. If the index number of the full Binary Tree node in the array is I, it has the following properties. (1) If I = 0, this node is the root node and has no parent nodes. (2) If I> 0, the parent node is (I-1)/2. (Note that the division here is division, and the fractional part in the result will be discarded .) (3) The left child of node I is 2i + 1, and the right child is 2i + 2. (4) If I> 0, When I is an odd number, it is the left child of the parent node, and its brother is I + 1; when I is an even number, it is the right child of a dual-node, and its brother node is I-1. (5) the depth of k full binary tree needs to be 2 K-1 array for storage. The above properties show that it is very convenient to store nodes full of Binary trees using arrays. You can easily calculate the numbers of nodes such as parent, child, and brother Based on the index number of a node, to access these nodes, This is the simplest and most spatial method to store binary full or full Binary Trees. In order to reflect the logical relationship between nodes by using the location of nodes in the array, when storing Binary Trees, you only need to set the location of the empty nodes in the array to null, the effect is shown in Figure 6.8 (B. This will cause a certain amount of space waste, but if the number of empty nodes is not large, these waste can be ignored. A depth of k binary tree needs 2 K-1 storage space, when the k value is very large and a lot of empty nodes of the binary tree, the worst case is that each layer has only one node, using the sequential storage structure to store data is obviously a huge waste. In this case, we should use a chain storage structure to store data in Binary Trees. 2. Chain storage structure the chain storage structure of the binary tree can be divided into two-fork linked list and three-fold linked list. In a binary linked list, each node not only stores its own data, but also sets two pointer fields left and right, which point to left and right respectively, when you need to find the parent of a node in a binary tree, you can add a pointer to the parent field parent for each node. 3. Binary Tree depth first traversal 1. First traversal if the binary tree is not empty, the process is: (1) access the root node. (2) traverse the left subtree in sequence. (3) traverse the right subtree in sequence. In Figure 6.13, the first-order traversal is to connect the nodes marked as (1) by the order of Access to the search path. The result is ABDECF. 2. If the binary tree is not empty, the process is as follows: (1) traverse the left subtree in the middle order. (2) access the root node. (3) traverse the right subtree in the middle order. In Figure 6.13, the first order traversal is to connect the nodes marked as (2) by the order of Access to the search path. The result is: DBEACF. 3. perform post-order traversal. If the binary tree is not empty, the process is as follows: (1) traverse the left subtree in descending order. (2) traverse the right subtree in descending order (3) Access the root node.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.