Abstract Data Types in C

  • Interface declares operations, not data structure
  • Implementation is hidden from client (encapsulation)
  • Use features of programming language to ensure encapsulation

Common practice

  • Allocation and deallocation of data structure handled by module
  • Names of functions and variables begin with <modulename>_
  • Provide as much generality/flexibility in interface as possible
  • Use void pointers to allow polymorphism

#ifndef ARRAY_H

#define ARRAY_H

typedef struct Array *Array_T;

extern Array_T Array_new(void);

extern void Array_free(Array_T array);

extern void Array_insert(Array_T array, void *datap);

extern void Array_remove(Array_T array, void *datap);

上一篇:BZOJ4003 [JLOI2015]城池攻占 左偏树 可并堆


下一篇:C\C++与Java中的static关键字