Several C ++ data structures

zhaozj2021-02-16  84

If you need to reprint, please contact the author.

Several C data structures are updated on August 17

Author: Zheng Wei pro_zw@sina.com.cn

Code download

Disclaimer: Using these classes is the user's voluntary behavior, the author does not provide any form of guarantee for the quality of the source code, if the user is not related to the author because any losses caused by using these classes, the author does not assume any responsibility.

Array.h: Safe array, automatically grows the size (can be randomly accessed, but the expansion is very low, so try to choose the appropriate size when initialization)

LinkedList.h: Normal Links (can be randomly accessed, but the random access efficiency is low, it is achieved by looping to the specified location)

DclinkedList.h × two-way circular chain (not random access, but can be forward, reverse cycle, and most of the operation is higher than ordinary chain), recommended)

Hashtable.h: hash table (using key value identification elements, the same element is considered to be the same element)

Set.h: Collection (derived from dclinkedList, basically, only when inserting, the elements will not be repeated)

Stack.h: Stack (internally using dclinkedList members, the code is simple and will not overflow)

Binstree.h: binary search tree (element is not repeated)

Avltree.h ×: AVL balance tree (element is not repeated)

Gentree.h ×: General Tree (Using Binary Tree Method)

DFA.H: Universal Automata (Automata Implemented by HashTable)

× Bidirectional loop linked list Although the memory is much larger than the ordinary linked list, most of the operations are highly efficient than ordinary linked objects. If you don't need a random access, it is recommended (where the random access efficiency of the list is very low, if you often need random Access, or use the security array), HashTable.h is difficult to use the two-way circular chain table (see it later) due to the special cause of the code, pay attention to how the two-way circular chain is determined to reach the end.

× AVL tree is very high, and this class does not fully implement (for example, delete functions), but the AVL's search efficiency is extremely high, so it is suitable for data sets that are often searching in the initialization program before the program. The binary search tree is already enough.

× General Tree Since is not a linear table, many functions, usage methods are not very different from other classes (in fact the binary search tree and AVL balance trees can be viewed, but the general tree is not)

All classes are written using templates and are not specific to the Windows platform, all of which can be used with an operation platform with a C compiler.

The above code is rewritten on the author photo, and has not been strictly tested. If any problems, difficulties, source code errors, or improved places are discovered during use, very welcome to discuss. Email address: Pro_zw@sina.com.cn.

The author will continue to improve the various types and increase the new data structure according to the problems discovered, so that it continues to improve.

The user can also change the code as needed, but I hope to send the result after the change, which is also hoping to refer to the opinions of all aspects and improve the code, and have not interest.

bibliography:

"Data Structure - C Language Description" William Ford William TOPP Tsinghua University Press "Computer Program Design Art" Donald E.Knuth "Tsinghua University Press

转载请注明原文地址:https://www.9cbs.com/read-13630.html

New Post(0)