06th.pdf - CS 126 Lecture P5 Abstract Data Type Outline...

This preview shows page 1 - 9 out of 12 pages.

CS 126 Lecture P5: Abstract Data Type CS126 6-1 Randy Wang Outline Introduction Stacks (and queues) Stack and queue applications
CS126 6-2 Randy Wang Data Type and ADT CS126 6-3 Randy Wang Interface, Implementation, and Client Volum e C hannel C lient In terface Im plem entation
CS126 6-4 Randy Wang Advantages of ADT CS126 6-5 Randy Wang “Non-ADTs” interface: typedef struct {int p; int q;} Rational; client: Rational a; a.p = 3; Non-ADT interface: typedef struct {int p; int q;} Rational; client: Rational a; setRationalP(&r, 3); void setRationalP(Rational *r; int x); ADT implementation: void setRationalP(Rational *r; int x) {r->p = x;}
CS126 6-6 Randy Wang Outline Introduction Stacks (and queues) Stack and queue applications CS126 6-7 Randy Wang Stack and Queue Definitions
CS126 6-8 Randy Wang Interface, Implementation, and Client “Client” needs to know how to use the “interface” “Implementation” needs to know what “interface” to implement Volum e C hannel C lient (m yprog.c) In terface (stack.h ) Im plem entation (stack.c) #include #include
Post-increment: s[N] = item; N+=1; Pre-decrement: N-=1; return s[N]; Index of 1st empty slot Time
Opposite of malloc : gives memory back to computer CS126 6-13 Randy Wang Demo Linked List Stack
for array CS126 6-15 Randy Wang Outline Introduction Stacks (and queues) Stack and queue applications

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture