Abstract Data Types

An abstract data type (ADT) is a name (the type-name) and a list of the actions that can be performed on it.

For example, consider the INTEGER_STACK ADT. The actions on it are:

In C, the ADT type-name is defined using typedef. The actions are implemented as functions. The actions and the type-name are grouped together in a single .h header file.


	/* integer stack ADT */
	typedef struct int_stack * int_stack;

	int_stack make_int_stack(void);
	void      destroy_int_stack(int_stack);
	void      push_int_stack(int_stack, int);
	int       top_int_stack(const int_stack);
	void      pop_int_stack(int_stack);
	int       is_empty_int_stack(const int_stack);

We are assuming that this ADT (and, in general all ADTs) will be heap allocated. Therefore, in C:

We have also used some other conventions.

That is all that belongs in the header file; in particular there are no implementation details.


Next Prev Main Top Feedback