Thoughts on reading rectification C language data structure (1)

Source: Internet
Author: User

1. What is a data structure?

Data structure, is our computer internal operation, programming language basic work Mode bar, personal summary = =!!

Data: The simple point is that the computer binary machine code, and then through a number of complex operations, into a complex language.

Data element: The data has the difference between the set and the element, the individual in the collection is the data element, the relative is the structure.

Linear table:

To put it simply, it is a linear storage structure with a large number of elements in each table that are connected in a physical location.

These elements have direct precursors and direct successors. The position of the linear table is adjacent.

For example, position 1, Position 2, Position 3 ... Position N.

There is also a point where the data of a linear table, no matter how large, is fixed, that is, there is an end point.

Disadvantages of linear tables: when inserting deletes, you need to move a large number of elements.

For example, inserting and deleting elements will move the insert or delete all subsequent elements, resulting in a linear increase in time complexity.

Chained storage structure:

Each node has a pointer field and a data field, where the pointer field points to the next successor of the element, such that the reciprocating loop

Can form a list, of course, this and the chain storage structure also has a different place, the biggest difference is that their "address" is different.

A chained storage structure relies on pointers to determine the exact location of his next element, while a linear table is judged by the physical location of the address.

Make the simplest analogy, a game, if I want to go to a far away map. There are 2 ways: the first, walk directly,

Then I will go through all the areas of this map, until I reach this map, and another way is to use the cash, the mall,

Then just point to the map and you can move to where I want it instantly.

The pros and cons of 2 ways is obvious, if the use of chain structure, no matter how far apart, I just a little mouse,

It is possible to delete the insertion element, and if you insert or delete an element, the position of the element associated with the element will be shifted by using a linear table. In the case of a chained storage structure, I simply insert or delete this element and then point the previous element's next to the next of the newly inserted element, and then the pointer to the element in front of the element that the newly inserted element is assigned to is OK.

A linked list has a pointer field, and the pointer points to the next element in the linked list. So how do we insert the element in the linked list.

First we have to think that the inserted element is not the head of the list, or the tail of the list. Or in the middle of the list,

Either before or after the a element. Now let's discuss the method of inserting elements in the middle section.

The first thing that makes S->next=p->next this sentence is that the pointer to the next element of the linked list P is assigned to the pointer to the next element in S's direction.

So the s->next becomes p->next, because it is inserted in the middle of the list, so the natural s->next points to the next element in the linked list.

P->next=s, the meaning of this sentence: is the value of the pointer s, so that the p->next point to S, so that the front and back 2 aspects are integrated into the list, which makes a part of the list, which is the insertion method.

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.