70 likes | 355 Views
An abstract data type (ADT) is a contract between the user of a data structure and its implementor. An ADT specifies: type of data stored (e.g. any objects, or only ints) available methods, with parameter and return types error conditions associated with methods
E N D
An abstract data type (ADT) is a contract between the user of a data structure and its implementor. An ADT specifies: type of data stored (e.g. any objects, or only ints) available methods, with parameter and return types error conditions associated with methods (optionally) performance guarantees, in terms of space and/or time Can be very simple (list) or very complex (stock exchange). Abstract Data Types (ADTs) Stacks
Benefits of ADTs • encapsulation: less to worry about • division of labor • promotes code sharing • cheaper sub-contracts • facilitates unit-testing Stacks
The List ADT models a sequence of positions storing arbitrary objects It establishes a before/after relation between positions Can be implemented in various ways: array singly-linked doubly-linked Accessor methods: first(), last() prev(p), next(p) Update methods: replace(p, e) insertBefore(p, e), insertAfter(p, e), insertFirst(e), insertLast(e) remove(p) convenience methods: isEmpty() List Abstract Data Type (ADT) Stacks
The Position ADT models the notion of place within a data structure where a single object is stored It gives a unified view of diverse ways of storing data, such as a cell of an array a node of a linked list Just one method: object element(p): returns the element stored at position p Position ADT Stacks