2, Toad's data structure note of the two linear table

Source: Internet
Author: User

2, Toad's data structure note of the two linear table

By the second note, each note should be preceded by a statement to inspire yourself and your little partner.

"The most important thing in life is not the position, but the direction of progress."

This time we study the table, yes is the table. What table? Well, Chinese characters are really profound, yes, just a watch. Don't think it's crooked.

Welcome reprint, Reproduced please indicate the source:

1. Definition

Linear tables (also known as sequential tables) are the most basic, simplest, and most commonly used data structures . The relationship between data elements in a linear table is a one-to-one relationship, that is, except for the first and last data elements, the other data elements are both end-to-tail. The logic structure of linear table is simple and easy to implement and operate. Therefore, the data structure of linear table is widely used in practical application.

Friends who have contacted the database know that there are tables in the database, as well as the definitions here.

In practical applications, linear tables are used in the form of stacks , queues , strings and other special linear tables .

2. Structural features

The linear table has the following structural features:

1. uniformity : Although the data elements of different data tables can be various, the data elements of the same linear table must have the same data type and length.

2. order : The position of each data element in the linear table depends only on their ordinal, the relative position of the data element is linear, that is, there is a unique "first" and "last" data element, except the first and last, The other elements are preceded by only one data element (direct precursor) and only one data element behind it (direct successor).

3. Storage implementation

In order to realize the storage aspect of linear table data elements, there are two methods of sequential storage structure and chained storage structure generally available.

3.1 Sequential storage structure

Each data element of a linear table is stored sequentially in a computer with a contiguous set of storage cells , called the sequential storage structure of the linear table.

The primary advantage of a sequential storage structure is that it saves storage space , because the storage unit allocated to the data is used to store the node's data (regardless of the size of the array in C/s + + language), The logical relationship between nodes does not occupy additional storage space. Using this method, the random access to the node can be achieved, that is, each node corresponds to a sequence number, which can be calculated directly from the storage address of the node. But the main disadvantage of the sequential storage method is that it is not easy to modify, and it is possible to move a series of nodes when inserting or deleting nodes.

3.2 Chain storage structure

The data element of a linear table is stored in a computer with a set of arbitrary storage units (this set of storage units can be contiguous or discontinuous).

It does not require logically adjacent elements to be adjacent to the physical location. Therefore, it has no sequential storage structure of the weaknesses, but also lost the sequential table can be random access advantages.

4. Dynamic Storage Allocation

Let's take a look at the code below:

#include "Stdio.h"

#include "Stdlib.h"

void Main ()

{

int I,*pi;

float F,*PF;

PI = (int *) malloc (sizeof(int));

PF = (float *) malloc (sizeof(float));

*pi=1024;

*pf=3.14;

printf ("integer =%d,float =%f\n", *PI,*PF);

Free (PI);

Free (PF);

}

The code toad can be compiled and run through VS2012, and the small partners can run through any C compiler.

Output Result:

such as 1:


The malloc function can request the required space and, if there is space, returns a pointer to the starting address of the storage space of the desired size. It is then freed by calling the free function. If not released, then the program can no longer find this storage space, that is, we often say the memory leak.

2, Toad's data structure note of the two linear table

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.