Class Notes (837,449)
Canada (510,273)
CS 138 (14)
Lecture 7

Data Lecture 7.docx

3 Pages
60 Views
Unlock Document

Department
Computer Science
Course
CS 138
Professor
Michael Godfrey
Semester
Winter

Description
Data Lecture 7 January 29, 2013 Static & Dynamic Memory Allocation  Memory/storage for your variables comes from one of two possible places 1. RUN-TIME STACK handles automated allocation & de-allocation for parameters and local variables as procedures are called  This storage automatically disappears when the procedure finishes executing 2. FREESTORE / THE HEAP handles all programmatic requests for storage via MALLOC and NEW (for objects, structs, and anything else C++ style)  Program must return this storage when done with it via FREE or DELETE  Ex: o Ballon *b = new Balloon;  Pointer b is stored on stack  Object it points to is on heap struct Node { string val; Node* next; }; int main(...) { Node *p; // p is pointer p = new Node; p -> val = "first"; p -> next = NULL; Node* q,r; // q is pointer, r is NODE r.val = "flurble"; q = new Node; q -> next = p; q -> val = "second"; Node* s = new Node; // s is pointer s -> val = "third"; s -> next = q; Node temp=s; while (NULL != temp) { cout< val << endl; temp = temp-> next; } } ADTs  An abstract data type is a structure that s well defined & recognizable behavior o It contains data that may be accessed only in a prescribed manner by set of operations  Each operation has o SIGNATURE (interface)  Describes parameters & return type o PRE-CONDITION (logic statement)  States what must be true before operation may be applied o POST-CONDITION (logic struct)  Describes effects of executing operation  Formality & rigour vary greatly  Examples o A vector/sequence is an ordered data container that allows random access to individual elements o A stack is an ordered data container with LIFO (last in first out) policy on inserts/deletes  No random access to elements o A queue is an ordered data container with FIFO (first in first out) policy on inserts/deletes
More Less

Related notes for CS 138

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit