


What is the data structure in c language? What are the common data structures?
In the C language, a data structure refers to a collection of data elements that have one or more specific relationships with each other. It is a way for computers to store and organize data; common data structures include: linear data structures ( Array, linked list, stack, queue and linear list), tree structure (binary tree, complete binary tree, binary search tree, heap), graph structure (directed graph and undirected graph).
The operating environment of this tutorial: windows7 system, c99 version, Dell G3 computer.
What is a data structure?
Data structure is the way computers store and organize data. A data structure refers to a collection of data elements that have one or more specific relationships with each other
The implementation of most data structures requires the help of pointers and structure types in the C language
Next, let’s get to today’s focus. O(∩_∩)O Several common data structures
(1) Linear data structure: There is generally a one-to-one relationship between elements, which is the most commonly used A type of data structure, typically: arrays, stacks, queues and linear tables
(2) Tree structure: There is a hierarchical relationship between nodes, and a node in each layer can and can only be combined with A node on the upper layer is related, but it can be related to multiple nodes on the next layer at the same time, which is called a "one-to-many" relationship. Common types are: tree, heap
(3) Graphic structure : In the graph structure, multiple nodes are allowed to be related, which is called a "many-to-many" relationship
The following is a brief introduction to each of these data structures:
1. Linear data structures: Typical ones are: arrays, stacks, queues and linear tables
(1) Arrays and linked lists
a. Array: stores a group of data of the same type. The length of the array needs to be specified in advance, such as one-dimensional array, two-dimensional array, multi-dimensional array, etc.
b. Linked list: Linked list is a type of C language A widely used structure, it is implemented in the form of dynamically allocated memory, using a set of arbitrary storage units to store a linked list of data elements. Generally, a pointer field is added for each element to point to subsequent elements
c, arrays The difference from a linked list:
From a logical structure perspective: arrays must have a fixed length defined in advance and cannot adapt to the dynamic increase or decrease of data; linked lists dynamically allocate storage and can adapt to the dynamic increase or decrease of data. situation, and can easily insert and delete data items (when inserting or deleting data items in the array, other data items need to be moved)
From the memory storage point of view: (static) the array allocates space from the stack (using NEW is created in the heap), which is convenient and fast for programmers, but has a small degree of freedom; linked lists allocate space from the heap, which has a large degree of freedom but is troublesome to apply for and manage.
From the perspective of access methods: the array is in memory It is stored continuously, so you can use subscript indexes for random access; the linked list is a linked storage structure, and elements can only be accessed sequentially from front to back in a linear manner, so the access efficiency is lower than that of arrays
(2) Stack, queue and linear table: sequential storage and chain storage methods can be used for storage
Sequential storage: with the help of the relative position of data elements in the storage space Position to represent the logical relationship between elements
Chain storage: Use pointers representing the storage addresses of data elements to represent the logical relationship between elements
a. Stack: only allowed at the end of the sequence Operations, stack operations can only be performed on the top of the stack. Generally, the stack is also called a last-in-first-out or first-in-last-out linear structure
Sequential stack: A stack using a sequential storage structure is called a sequential stack, that is, it needs A space with consecutive addresses is used to store the elements of the stack. The type of the sequential stack is defined as follows:
Chain stack: A stack using a chain storage structure is called a chain stack:
b. Queue: Only operations are allowed at both ends of the sequence. Generally, the queue is also called a first-in, first-out linear structure.
Circular queue: A sequential storage structure is used. Queue needs to allocate storage space according to the maximum possible length of the queue. Its type is defined as follows:
Chain queue: A queue using a chain storage structure is called a chain queue. Generally, it needs Setting the head and tail pointers is just the head and tail nodes of the linked list:
c. Linear table: allows operations at any position in the sequence. The operation position of the linear table is not restricted. Table operations are very flexible. Common operations include inserting and deleting at any location, and querying and modifying elements at any location
Sequential table: A linear table represented by a sequential storage structure is called a sequential table. A set of storage units with consecutive addresses is used to store the data elements of the linear table at one time, that is, the adjacent storage locations represent the sequence between two elements. In order to avoid moving elements, in order to avoid moving elements, generally only inserting and deleting elements at the end of the table is considered in the interface definition of the sequence table. The sequence table implemented in this way can also be called a stack table:
Linear lists: generally include singly linked lists, doubly linked lists, circular linked lists and two-way circular linked lists
Singly linked lists:
Double linked lists :
Comparison of two storage structures of linear tables:
Sequential tables:
Advantages: In sequential tables, logic is relatively Two adjacent elements are also physically adjacent, making it easier to search. The time complexity of accessing any element is O(1)
. Disadvantages: Not suitable for inserting or deleting elements at any position. Because elements need to be moved, the average time complexity is O(n)
Linked list:
Advantages: To insert or delete an element at any position of the link, you only need to modify the corresponding pointer, and there is no need to move the element; Dynamic allocation on demand, no need to pre-allocate a continuous empty space according to the maximum demand
Disadvantages: It is inconvenient to search. To find an element, you need to start from the head pointer and search along the pointer field, so the average time complexity is O(n)
2. Tree structure: There is a hierarchical relationship between nodes. A node in each layer can and can only be related to one node in the previous layer, but it can also be related to multiple nodes in the next layer. Nodes are related, which is called a "one-to-many" relationship. Common types are: tree, heap
(1) Binary tree: A binary tree is a recursive data structure that contains n (n>=0) nodes. A finite set of points. A binary tree has the following characteristics:
A binary tree can be an empty tree; each node of a binary tree has exactly two subtrees, one or two of which may be empty; each node in a binary tree The positions of the left and right subtrees cannot be reversed. If the positions of the two are changed, it will become another binary tree
(2) Complete binary tree: starting from the root, top to bottom, left to right, Each node of a full binary tree is numbered consecutively from 1 to n. If each node corresponds one-to-one with the nodes numbered from 1 to n in the full binary tree of depth k, it is called a complete binary tree
a. Use a sequential storage structure: use a one-dimensional array to store a complete binary tree. The number of the node is related to the subscript of the node (for example, the root is 1, then the left child of the root is 2i=21=2, and the right child is 2i 1=21 1=2)
(6) Heap: A heap is a complete binary tree with the following characteristics: all non-leaf nodes are no larger than (or no smaller than) its left and right child nodes. If all non-leaf nodes in the heap are not larger than their left and right child nodes, it is called a small top heap (small root heap). If all non-leaf nodes in the heap are not smaller than their left and right child nodes, it is called a large heap. Top heap (big root heap)
(7) Union-find: Union-find refers to a set composed of a set of disjoint subsets, denoted as: S= {S1,S2,S3,…,Sn}
(8) B-tree
3. Graph structure: In the graph structure, correlation between multiple nodes is allowed. It is called a "many-to-many" relationship and can be divided into directed graphs and undirected graphs
Tutorial recommendation: "c language tutorial video"
The above is the detailed content of What is the data structure in c language? What are the common data structures?. For more information, please follow other related articles on the PHP Chinese website!

To start C#.NET development, you need to: 1. Understand the basic knowledge of C# and the core concepts of the .NET framework; 2. Master the basic concepts of variables, data types, control structures, functions and classes; 3. Learn advanced features of C#, such as LINQ and asynchronous programming; 4. Be familiar with debugging techniques and performance optimization methods for common errors. With these steps, you can gradually penetrate the world of C#.NET and write efficient applications.

The relationship between C# and .NET is inseparable, but they are not the same thing. C# is a programming language, while .NET is a development platform. C# is used to write code, compile into .NET's intermediate language (IL), and executed by the .NET runtime (CLR).

C#.NET is still important because it provides powerful tools and libraries that support multiple application development. 1) C# combines .NET framework to make development efficient and convenient. 2) C#'s type safety and garbage collection mechanism enhance its advantages. 3) .NET provides a cross-platform running environment and rich APIs, improving development flexibility.

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

C# and .NET adapt to the needs of emerging technologies through continuous updates and optimizations. 1) C# 9.0 and .NET5 introduce record type and performance optimization. 2) .NETCore enhances cloud native and containerized support. 3) ASP.NETCore integrates with modern web technologies. 4) ML.NET supports machine learning and artificial intelligence. 5) Asynchronous programming and best practices improve performance.

C#.NETissuitableforenterprise-levelapplicationswithintheMicrosoftecosystemduetoitsstrongtyping,richlibraries,androbustperformance.However,itmaynotbeidealforcross-platformdevelopmentorwhenrawspeediscritical,wherelanguageslikeRustorGomightbepreferable.

The programming process of C# in .NET includes the following steps: 1) writing C# code, 2) compiling into an intermediate language (IL), and 3) executing by the .NET runtime (CLR). The advantages of C# in .NET are its modern syntax, powerful type system and tight integration with the .NET framework, suitable for various development scenarios from desktop applications to web services.

C# is a modern, object-oriented programming language developed by Microsoft and as part of the .NET framework. 1.C# supports object-oriented programming (OOP), including encapsulation, inheritance and polymorphism. 2. Asynchronous programming in C# is implemented through async and await keywords to improve application responsiveness. 3. Use LINQ to process data collections concisely. 4. Common errors include null reference exceptions and index out-of-range exceptions. Debugging skills include using a debugger and exception handling. 5. Performance optimization includes using StringBuilder and avoiding unnecessary packing and unboxing.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor