Stack and queue --Linux C programming stop learning

The concept of a data structure

Data structure is the organization of the data. Program data used are not isolated, but there are interrelated, depending on demand access to data, the same data can be organized in many different ways.
Organization of data storage and access contains two meanings this way, the two are closely linked. For example, storage array element is continuous.

Stack

Collection is a set of data stack, which is limited to the Push access rules (stack), Pop (pop) both.
For purposes of the stack, after the first elements of the stack push, push element after the first stack, so the stack data structure of such features can be summarized as LIFO (Last In First Out, LIFO).

Depth-first search (DFS)

I.e., depth-first algorithm known in space, all possible search results, for loop can achieve the same effect, but its time complexity is much higher than the depth-first algorithm.
The core depth-first algorithm is recursive , we need to work by means of a recursive stack, so its space complexity is O (N)
The idea is: what to do to solve the moment, the next step to repeat the operation. Depth-first search is one way to, there does not meet the conditions on the back, and it continues to meet the conditions.

Queues and breadth-first search (BFS)

Set of elements is a collection of queues, but also provides two basic operations: Enqueue (enqueued) to add elements to the tail, the Dequeue (dequeued) removing the elements from the queue head and returned. Like just queue up for tickets, first come first serve, first-in-first-out team who is also the team, this is called FIFO (First In First Out, First In First Out).

BFS explore every step from every direction, to push further forward. BFS can find the shortest path from the beginning to the end, but not necessarily depth-first search to find the shortest path.
Shortcoming BFS out: In the hierarchy tree deeper & more child nodes of the case, the memory consumption is very serious. The small number of BFS suitable node's children, and the situation is not hierarchical tree too deep.

Circular queue

If you need to use team lists team element position, consider using a circular queue.
Circular queue: the queue array thought of as a circle, still head and tail pointers has been increased, when referring to the end of the array will automatically return to the beginning of the array, is an effective element between the head of the queue to the tail, the tail from empty memory locations between the head, it means that if the head catch tail queue empty, it means that if the head catch tail queue memory is full.
Circular queue

Published 39 original articles · won praise 4 · Views 1122

Guess you like

Origin blog.csdn.net/qq_41403559/article/details/104296862