1 / 11

Definition of a structured set

Definition of a structured set. Definition (structured set) A structured set is a set in the mathematical sense, where the elements satisfy some relations between them. Short:. structured set Sr = set S + relation R.

Download Presentation

Definition of a structured set

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Definition of a structured set Definition (structured set) A structured set is a set in the mathematical sense, where the elements satisfy some relations between them. Short: structured set Sr = set S + relation R

  2. Graphical representation of a set, and linear, tree and graph structures

  3. Definition of an ADT Object Definition (ADT Object) In the context of abstract data type (ADT), we define an ADT objectas a structured set of elements (i.e. a set where the elements satisfy some relation R between them), supplied with operations acting on these elements and which must ensure that the relation R is guaranteed. Short: ADT object = set S + relation R + Operations O

  4. SR, DT and ADT implementation approaches

  5. Operations Constructor Functions • create(&o, c) • destroy(&o) Manipulator Functions • put(o,&e) : adds element *e in P order to o. • get(o,&e) • new_capacity(o,c) Access Functions • consult(o,&e) : copies the element in P order from o to *e. • is_empty(o) • is_full(o) • … Traverse Function • traverse(o, f, &b) : calls the user supplied function f for all elements of o, using the buffer b.

  6. Data Type Specification For an array implementation typedef struct obj_descr_t { elt_t *base; //points to element base[0] of //the ADT object array instance ... //all what is needed for the impl. of the //ADT object fcts } obj_descr_t;

  7. Data Type Specification For a linked list implementation typedefstructp_node_t { //p stands for protocol P //of the ADT oject elt_t: e; //element to be stored in a node ... //all what is needed for the impl. of the ADT //object protocol P } p_node_t; typedefstructobj_descr_t { p_node_t*root; //points to the entry element of the ADT object instance ... //all what is needed ... } obj_descr_t;

  8. Generic array and linked list implementation

  9. stack_create() (c3) s (c4) (m3) s (m1) sd elt a elt a (m2) (c1) sd->top (c2') (c2) typedef charelt_t; typedef void *stack_t; stack_t *stack_create(void) { (c1) stack_descr_t *sd; (c2) sd = malloc(sizeof *sd); (c3) sd->top = NULL; (c4) return sd; } typedef struct stack_node_t { elt_t e; struct stack_node_t *previous; } stack_node_t; typedef struct stack_descr_t { stack_node_t *top; } stack_descr_t; main() { (m1) stack_t s; (m2) elt_t elt = 'a'; (m3) s = stack_create(); (m4) stack_put(s,&elt); } Imperative & System Programming, B. Hirsbrunner, diuf.unifr.ch/pai/ip Session 9, 13 November 2013

  10. stack_put(s,&e) (p1) (p1) s e (p5) (p2') (p1) s–>top s (p3) s a a (p4) elt elt a a (p2'') new_node (p2) (m4) stack_put(s,&elt); (p1) void stack_put(stack_t s, elt_t *e) { (p2) stack_node_t *new_node = malloc(sizeof(stack_node_t)); (p3) new_node->e = *e; (p4) new_node->previous = s->top; (p5) s->top = new_node; } typedef charelt_t; typedef void *stack_t; typedef struct stack_node_t { elt_t e; struct stack_node_t *previous; } stack_node_t; typedef struct stack_descr_t { stack_node_t *top; } stack_descr_t; Beware, there is a little error in 'stack_put' : the generic pointer 's' can't be dereferenced without casting: ((stack_descr_t *) s) –> top

More Related