Skip to main content

Data Structures in C (1)

Basic data types, linear and nonlinear structures, GLib and the C++ STL.

ν•œκ΅­μ–΄ 원문

English edition note: These are historical study notes. The C++ standard library provided containers before C++11. The GLib/glibc comparison and the data-type table are informal summaries and need to be checked against the relevant language and library documentation.

#πŸ“š What is a data structure?

A typical programming process

  1. Understand and analyze the problem
  2. Design the program variables
  3. Design the program logic (algorithms and flowcharts)
  4. Write the program
  5. Run and debug the program

Data structures belong to the design of program variables:

  1. identify data objects and their attributes;
  2. define and implement relationships between data and the operations on them. They provide systematic and efficient methods for doing so.

Data types used in data structures

Data typeSet of data objectsExample operationsInternal representation
IntegerNumbers without a fractional part+, -, *, /, %, ++, β€”, (and others)Fixed-point representation
Real numberNumbers with a fractional part+, -, *, /, %, ++, β€”, (and others)Floating-point representation
CharacterThe character set defined by the computer system+, -, <, >, (and others)ASCII representation
ArrayA collection of values of the same typex[i]Sequential representation of homogeneous objects
StructureA collection of values of different typesx.memberSequential representation of heterogeneous objects

#πŸ“š Classification of data structures

  1. Data types provided by a programming language (basic representations of data objects)
  • Simple types: integer, real, character, Boolean and pointer types
  • Structured types: arrays, structures, strings and others
  1. Structures studied in a data structures course (representations for managing sets of data objects)
  • Linear list structures
    • Sequential list: an ordered list implemented using sequential mapping
    • Linked list: an ordered list implemented using nonsequential mapping
    • Stack: a last-in, first-out (LIFO) list
    • Queue: a first-in, first-out (FIFO) list
  • Nonlinear structures
    • Trees and binary trees: binary search trees, m-way search trees, heaps and others
    • Graphs: directed graphs, undirected graphs and others
    • Hash tables
    • Index trees: AVL trees, B trees, B+ trees, red-black trees and others

#πŸ“š Data structures in C (libraries)

C does not directly provide the data structures discussed here, so they must be implemented to use them. Third-party libraries do provide these data structures.

One is GLib.
(Take care not to confuse it with glibc.)

GLib and glibc compared

GLibglibc
Data structuresArrays, queues, linked lists, hash tables, trees and othersQueues, lists, trees and others
Object systemGObject-
IOiostream, file input/outputfopen, fwrite, fread, fclose and others

#πŸ“š Data structures in C++ (STL)

Since the C++11 standard, containers (data structures) and algorithms are provided by the standard library.

  1. STL means
  • Standard Template Library What is a template: C++

Connect