03-ATDs - Ab Abstract Data Types Continuation This material...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Abstract Data Types Abstract Data Types – Continuation Continuation This material is based on contents of the book: “C Interfaces and Implementations”, from David R. Hanson. Parts also under permission from Princeton University. USF – COP4530 – Data Structures Summer 2009 1of45 ceto U e s ty
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Include modules more than once What is key in this code? – Stack.h: #ifndef STACK_INCLUDED #define STACK_INCLUDED typedef struct Stack_T *Stack_T; extern Stack_T Stack_new (void); extern int Stack_empty(Stack_T stk); extern void Stack_push(Stack_T stk, void *x); extern void *Stack_pop(Stack_T stk); xtern void Stack free(Stack T *stk); extern void Stack_free(Stack_T *stk); #endif – Conditional compilation directives #ifdef and #endif and #define for STACK_INCLUDED permit stack.h to be included more than once – Typical when interfaces import other interfaces USF – COP4530 – Data Structures Summer 2009 2of29
Background image of page 2
Another way to hide details Recall from previous class, this is one way PQInterface.h // Defines types PQItem and PriorityQueue #include “PQTypes.h” // Define the function prototypes for functions that can be used by external users of the priority queue module xtern void Initialize (PriorityQueue *); /creates an empty queue extern void Initialize (PriorityQueue ); //creates an empty queue extern int Empty (PriorityQueue *); //true if PQ is empty extern int Full (PriorityQueue *); //true if PQ is full //puts the PQItem into the PriorityQueue extern void Insert (PQItem, PriorityQueue *); extern PQItem Remove (PriorityQueue *); //Removes an item USF – COP4530 – Data Structures Summer 2009 3of45
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Another way to hide details Details are here … – PQTypes.h: / //----------------------------------------------------------- #define MAXCOUNT 10 typedef int PQItem; typedef PQItem PQArray[MAXCOUNT]; typedef struct { int Count; PQArray ItemArray; }PriorityQueue; //----------------------------------------------------------- he file QImplementation c – The file PQImplementation.c //----------------------------------------------------------- #include <stdio.h> #include “PQInterface.h” void Initialize(PriorityQueue *PQ){ PQ->Count = 0; } USF – COP4530 – Data Structures Summer 2009 4of45
Background image of page 4
Another way to hide details What is also key in this code? – Stack.h: #ifndef STACK_INCLUDED #define STACK_INCLUDED typedef struct Stack_T *Stack_T; extern Stack_T Stack_new (void); extern int Stack_empty(Stack_T stk); extern void Stack_push(Stack_T stk, void *x); extern void *Stack_pop(Stack_T stk); xtern void Stack free(Stack T *stk); extern void Stack_free(Stack_T *stk); #endif – The typedef defines the type Stack T, a pointer to a yp yp _ ,p structure with a tag of the same name – This an opaque pointer type , clients can manipulate such pointers freely, but not dereference them USF – COP4530 – Data Structures Summer 2009 – Clients can’t look at the innards of the structure pointed to 5of29
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ADTs for User Interfaces User interfaces require some design The use of modules can help dividing a project BS example: Pocket calculator WBS example: Pocket calculator – Top level program calls on two modules – CalculatorModule: Provides calculator’s user-interface – YourCalculationModule: • accepts a string of characters (arithmetic expression given by user) • Evaluates expression to get an answer USF – COP4530 – Data Structures Summer 2009 6of29
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 43

03-ATDs - Ab Abstract Data Types Continuation This material...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online