Notes for Lecture 14 - March 6, 2007 ==================================== * Linear data structures ** Edit buffer ADT (text, chapter 9) NewBuffer() FreeBuffer() MoveCursorForward() MoveCursorBackward() MoveCursorToStart() MoveCursorToEnd() InsertCharacter() DeleteCharacter() DisplayBuffer() *** Array implementation struct bufferCDT { char text[MaxBuffer]; int length; int cursor; }; **** Advantages Cursor motion functions simple and constant time **** Disadvantages Insert and delete both Theta(n) operations Has predetermined max size. (Could overcome with datapack techniques.) *** Two stack implementation Consists of two stacks -- before and after. **** Advantages CursorForward, CursorBackward, InsertCharacter, DeleteCharacter constant time **** Disadvantages CursorToStart, CursorToEnd Theta(n) *** Linked list with dummy header implementation struct bufferCDT { cellT *start; cellT *cursor; }; **** Dummy header cell Convenient to have start point to a dummy cell, and dummy's next (link) pointer points to the chain of cells comprising the list. Cursor points to the cell containing the character immediately to left of cursor. **** Advantages CursorForward, InsertCharacter, DeleteCharacter constant time **** Disadvantages CursorToEnd and CursorBackward both expensive. *** Circular doubly linked list with dummy header implementation Each cell has a next and a prev pointer. Last element points to dummy. Dummy's prev points to last element. **** Advantages All operations constant time (except freeing a list) **** Disadvantages More memory, more time for simple operations. * Symbol table (a.k.a. dictionary) Set of (key, value) pairs. ** ADT *** symtab new_symtab() *** void free_symtab( symtab ) *** void insert( symtab table, char* key, void* value ) *** void* lookup( table, key ) ** Demo 14.1_symtab # Local Variables: # mode: outline # End: