ECE 2400 Computer Systems Programming Fall 2018 Topic 7: Concrete Data Types
|
|
- Bryce Robinson
- 5 years ago
- Views:
Transcription
1 ECE 2400 Computer Systems Programming Fall 2018 Topic 7: Concrete Data Types School of Electrical and Computer Engineering Cornell University revision: List CDTs List CDT Interface List CDT Implementation Vector CDTs Vector CDT Interface Vector CDT Implementation Comparing List and Vector CDTs 17 1
2 An algorithm is a clear set of steps to solve any problem in a particular problem class 1 def fib( n ): 2 3 if ( n == 0 ): return 0 4 if ( n == 1 ): return return fib( n-1 ) + fib( n-2 ) A data structure is a structured way of storing data chain of nodes each storing one integer linear array of integers The fib algorithms do not involve a data structure The chain and array data structures do not involve an algorithm Most interesting programs involve a combination of algorithms and data structures Think of algorithms as verbs and data structures as nouns Most interesting stories involve a combination of verbs and nouns 2
3 We can use a combination of algorithms and data structures to implement a concrete data type (CDT) A CDT includes both an interface and an implementation The interface specifies the what The implementation specifies the how Separating interface from implementation is called data encapsulation or information hiding 3
4 1. List CDTs 1.1. List CDT Interface 1. List CDTs Recall our example of a chain of dynamically allocated nodes Let s combine this data structure with a few simple algorithms to create a new concrete data type called a linked list 1.1. List CDT Interface 1 typedef struct 2 { 3 // implementation specific 4 } 5 list_int_t; 6 7 void list_int_construct ( list_int_t* this ); 8 void list_int_destruct ( list_int_t* this ); 9 void list_int_push_front ( list_int_t* this, int v ); 10 void list_int_reverse ( list_int_t* this ); void list_int_construct( list_int_t* this ); Construct the list initializing all fields in this list_int_t. void list_int_destruct( list_int_t* this ); Destruct the list by freeing any dynamically allocated memory used by this list_int_t. void list_int_push_front( list_int_t* this, int v ); Push a new value (v) at the front of this list_int_t. void list_int_reverse( list_int_t* this ); Reverse all values in this list_int_t. 4
5 1. List CDTs 1.2. List CDT Implementation Example of using list interface 1 int main( void ) 2 { 3 list_int_t list; 4 list_int_construct ( &list ); 5 list_int_push_front( &list, 12 ); 6 list_int_push_front( &list, 11 ); 7 list_int_push_front( &list, 10 ); 8 list_int_reverse ( &list ); 9 list_int_destruct ( &list ); 10 return 0; 11 } 1.2. List CDT Implementation 1 typedef struct _list_int_node_t 2 { 3 int value; 4 struct _list_int_node_t* next_p; 5 } 6 list_int_node_t; 7 8 typedef struct 9 { 10 list_int_node_t* head_p; 11 } 12 list_int_t; 5
6 1. List CDTs 1.2. List CDT Implementation Approach for implementing functions 1. Draw figure to explore high-level approach 2. Develop pseudo-code to capture high-level approach 3. Translate the pseudo-code to actual C code Pseudo-code for list_int_construct 1 void list_int_construct( list_int_t* this ) 2 set head ptr to NULL Pseudo-code for list_int_push_front After push front of value 12 After push front of value 11 6
7 1. List CDTs 1.2. List CDT Implementation After push front of value 10 1 void list_int_push_front( list_int_t* this, int v ) 2 allocate new node 3 set new node s value to v 4 set new node s next ptr to head ptr 5 set head ptr to point to new node Pseudo-code for list_int_destruct Dellocate head node? Dellocate head node s next pointer? 7
8 1. List CDTs 1.2. List CDT Implementation Need temporary pointer to point to next node! 1 void list_int_destruct( list_int_t* this ) 2 while head ptr is not NULL 3 set temp ptr to head node s next ptr 4 free head node 5 set head node ptr to temp ptr 8
9 1. List CDTs 1.2. List CDT Implementation 01 // Construct list 02 void list_int_construct( 03 list_int_t* this ) 04 { 05 this->head_p = NULL; 06 } // Push value on front of list 09 void list_int_push_front( 10 list_int_t* this, 11 int v ) 12 { 13 list_int_node_t* new_node_p 14 = malloc( sizeof(list_int_node_t) ); new_node_p->value = v; 17 new_node_p->next_p = this->head_p; 18 this->head_p = new_node_p; 19 } // Destruct list 22 void list_int_destruct( list_int_t* this ) 23 { 24 while ( this->head_p!= NULL ) { 25 list_int_node_t* temp_p 26 = this->head_p->next_p; 27 free( this->head_p ); 28 this->head_p = temp_p; 29 } 30 } // Main function 33 int main( void ) 34 { 35 list_int_t list; 36 list_int_construct ( &list ); 37 list_int_push_front( &list, 12 ); 38 list_int_push_front( &list, 11 ); 39 list_int_push_front( &list, 10 ); 40 list_int_destruct ( &list ); 41 return 0; 42 } ece2400-t07-ex1 stack heap 9
10 1. List CDTs 1.2. List CDT Implementation Interface vs. Implementation Implementation details are exposed in list_int_t A user can freely manipulate fields in list_int_t C does not provide any mechanism to enforce encapsulation Develop an algorithm for list_int_reverse 10
11 2. Vector CDTs 2.1. Vector CDT Interface 2. Vector CDTs Recall the constraints on allocating arrays on the stack, and the need to explicitly pass the array size Let s transform a dynamically allocated array along with its maximum size and actual size into a CDT 2.1. Vector CDT Interface 1 typedef struct 2 { 3 // implementation specific 4 } 5 vector_int_t; 6 7 void vector_int_construct ( vector_int_t* this ); 8 void vector_int_destruct ( vector_int_t* this ); 9 void vector_int_push_front ( vector_int_t* this, int v ); 10 void vector_int_reverse ( vector_int_t* this ); void vector_int_construct( vector_int_t* this ); Construct the vector initializing all fields in this vector_int_t. void vector_int_destruct( vector_int_t* this ); Destruct the vector by freeing any dynamically allocated memory used by this vector_int_t. void vector_int_push_front( vector_int_t* this, int v ); Push a new value (v) at the front of this vector_int_t. void vector_int_reverse( vector_int_t* this ); Reverse all values in this vector_int_t. 11
12 2. Vector CDTs 2.2. Vector CDT Implementation Example of using vector interface 1 int main( void ) 2 { 3 vector_int_t vector; 4 vector_int_construct ( &vector ); 5 vector_int_push_front( &vector, 12 ); 6 vector_int_push_front( &vector, 11 ); 7 vector_int_push_front( &vector, 10 ); 8 vector_int_reverse ( &vector ); 9 vector_int_destruct ( &vector ); 10 return 0; 11 } 2.2. Vector CDT Implementation 1 typedef struct 2 { 3 int* data; 4 size_t maxsize; 5 size_t size; 6 } 7 vector_int_t; To simplify our discussion in lecture, we will allocate a small array in the constructor, and then we assume we only push back a limited number of values 12
13 2. Vector CDTs 2.2. Vector CDT Implementation Approach for implementing functions 1. Draw figure to explore high-level approach 2. Develop pseudo-code to capture high-level approach 3. Translate the pseudo-code to actual C code Pseudo-code for vector_int_construct 1 void vector_construct( vector_int_t* this ) 2 allocate new array with eight elements 3 set vector s data to point to new array 4 set vector s maxsize to eight 5 set vector s size to zero Pseudo-code for vector_int_push_front Initial state of vector After push front of value 9 13
14 2. Vector CDTs 2.2. Vector CDT Implementation After push front of value 8 Implement moving down all of the elements 1 void vector_push_front( vector_int_t* this, int v ) 2 set prev value to v 3 for i in 0 to vector s size (inclusive) 4 set temp value to vector s data[i] 5 set vector s data[i] to prev value 6 set prev value to temp value 7 set vector s size to size + 1 Pseudo-code for vector_int_destruct 1 void vector_destruct( vector_int_t* this ) 2 free vector s data 14
15 2. Vector CDTs 2.2. Vector CDT Implementation 01 // Construct vector 02 void vector_int_construct( 03 vector_int_t* this ) 04 { 05 this->data = malloc( 8 * sizeof(int) ); 06 this->maxsize = 8; 07 this->size = 0; 08 } // Push value on front of vector 11 void vector_int_push_front( 12 vector_int_t* this, int v ) 13 { 14 int prev_value = v; 15 for ( size_t i=0; i<=this->size; i++ ) { 16 int temp_value = this->data[i]; 17 this->data[i] = prev_value; 18 prev_value = temp_value; 19 } 20 this->size += 1; 21 } // Destruct vector 24 void vector_int_destruct( 25 vector_int_t* this ) 26 { 27 free( this->data ); 28 } // Main function 31 int main( void ) 32 { 33 vector_int_t vector; 34 vector_int_construct ( &vector ); 35 vector_int_push_front( &vector, 12 ); 36 vector_int_push_front( &vector, 11 ); 37 vector_int_push_front( &vector, 10 ); 38 vector_int_destruct ( &vector ); 39 return 0; 40 } stack heap ece2400-t07-ex2 15
16 2. Vector CDTs 2.2. Vector CDT Implementation Interface vs. Implementation Implementation details are exposed in vector_int_t A user can freely manipulate fields in vector_int_t C does not provide any mechanism to enforce encapsulation Develop an algorithm for vector_int_reverse 16
17 3. Comparing List and Vector CDTs 3. Comparing List and Vector CDTs The list and vector CDTs have similar interfaces, but... very different execution times, and... very different space usage. Compare the execution time and space usage of the algorithms? Execution Time Space Usage Operation List Vector List Vector push_front push_back at find insert remove Compare the space usage of the data structure itself? An analysis of a CDT s execution time and space usage is usually a key part of the CDT s high-level specification 17
ECE 2400 Computer Systems Programming Fall 2017 Topic 7: C Lists and Vectors
ECE 2400 Computer Systems Programming Fall 2017 Topic 7: C Lists and Vectors School of Electrical and Computer Engineering Cornell University revision: 2017-09-29-08-04 1 Lists 2 1.1. List Interface................................
More informationECE 2400 Computer Systems Programming Fall 2018 Topic 8: Complexity Analysis
ECE 2400 Computer Systems Programming Fall 2018 Topic 8: Complexity Analysis School of Electrical and Computer Engineering Cornell University revision: 2018-10-11-00-23 1 Analyzing Algorithms 2 1.1. Linear
More informationECE 2400 Computer Systems Programming, Fall 2017 Prelim 1 Prep
revision: 2017-09-29-17-49 These problems are not meant to be exactly like the problems that will be on the prelim. These problems are instead meant to represent the kind of understanding you should be
More informationECE 2400 Computer Systems Programming, Fall 2017 Programming Assignment 2: List and Vector Data Structures
ECE 2400 Computer Systems Programming, Fall 2017 Programming Assignment 2: List and Vector Data Structures School of Electrical and Computer Engineering Cornell University revision: 2017-10-01-16-30 1.
More informationECE 2400 Computer Systems Programming Fall 2017 Topic 12: Transition from C to C++
ECE 2400 Computer Systems Programming Fall 2017 Topic 12: Transition from C to C++ School of Electrical and Computer Engineering Cornell University revision: 2017-10-23-01-13 1 C++ Namespaces 2 2 C++ Functions
More informationECE 2400 Computer Systems Programming Fall 2018 Topic 11: Transition to C++
ECE 2400 Computer Systems Programming Fall 2018 Topic 11: Transition to C++ School of Electrical and Computer Engineering Cornell University revision: 2018-10-19-09-50 1 Why C++? 3 1.1. Procedural Programming........................
More informationECE 2400 Computer Systems Programming, Fall 2018 PA2: List and Vector Data Structures
School of Electrical and Computer Engineering Cornell University revision: 2018-09-25-13-37 1. Introduction The second programming assignment is designed to give you experience working with two important
More informationECE 2400 Computer Systems Programming Fall 2018 Topic 6: C Dynamic Allocation
ECE 2400 Computer Systems Programming Fall 2018 Topic 6: C Dynamic Allocation School of Electrical and Computer Engineering Cornell University revision: 2018-10-11-00-22 1 Bookcase Analogy 2 2 Using malloc
More informationECE 2400 Computer Systems Programming Fall 2017 Topic 15: C++ Templates
ECE 2400 Computer Systems Programming Fall 2017 Topic 15: C++ Templates School of Electrical and Computer Engineering Cornell University revision: 2017-11-08-09-37 1 Function Templates 2 2 Class Templates
More informationCA31-1K DIS. Pointers. TA: You Lu
CA31-1K DIS Pointers TA: You Lu Pointers Recall that while we think of variables by their names like: int numbers; Computer likes to think of variables by their memory address: 0012FED4 A pointer is a
More informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 8: Dynamically Allocated Linked Lists 2017-2018 Fall int x; x = 8; int A[4]; An array is stored as one contiguous block of memory. How can we add a fifth element to the
More informationMidterm Review. CS 211 Fall 2018
Midterm Review CS 211 Fall 2018 BSB 250 Official Time: 10:00 am to 10:50 am If we can start a few minutes early, we will So try to arrive closer to 9:50am We will need to finish right at 10:50 since there
More informationECE 2400 Computer Systems Programming Fall 2018 Topic 2: C Recursion
ECE 2400 Computer Systems Programming Fall 2018 Topic 2: C Recursion School of Electrical and Computer Engineering Cornell University revision: 2018-09-13-21-07 1 Dictionary Analogy 2 2 Computing Factorial
More informationECE 2400 Computer Systems Programming Fall 2017 Topic 4: C Pointers
ECE 2400 Computer Systems Programming Fall 2017 Topic 4: C Pointers School of Electrical and Computer Engineering Cornell University revision: 2017-09-23-11-06 1 Pointer Basics 2 2 Call by Value vs. Call
More informationIn Java we have the keyword null, which is the value of an uninitialized reference type
+ More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are
More informationStructures and Pointers
Structures and Pointers Comp-206 : Introduction to Software Systems Lecture 11 Alexandre Denault Computer Science McGill University Fall 2006 Note on Assignment 1 Please note that handin does not allow
More informationECE 2400 Computer Systems Programming Fall 2017 Topic 14: C++ Inheritance
ECE 200 Computer Systems Programming Fall 2017 Topic 1: C++ Inheritance School of Electrical and Computer Engineering Cornell University revision: 2017-11-06-09-36 1 Introduction to C++ Inheritance 2 1.1.
More informationWeek 9 Part 1. Kyle Dewey. Tuesday, August 28, 12
Week 9 Part 1 Kyle Dewey Overview Dynamic allocation continued Heap versus stack Memory-related bugs Exam #2 Dynamic Allocation Recall... Dynamic memory allocation allows us to request memory on the fly
More informationCSE 143. Linked Lists. Linked Lists. Manipulating Nodes (1) Creating Nodes. Manipulating Nodes (3) Manipulating Nodes (2) CSE 143 1
CSE 143 Linked Lists [Chapter 4; Chapter 6, pp. 265-271] Linked Lists A linked list is a collection of dynamically allocated nodes Each node contains at least one member (field) that points to another
More informationCSC 1600 Memory Layout for Unix Processes"
CSC 16 Memory Layout for Unix Processes" 1 Lecture Goals" Behind the scenes of running a program" Code, executable, and process" Memory layout for UNIX processes, and relationship to C" : code and constant
More informationC-types: basic & constructed. C basic types: int, char, float, C constructed types: pointer, array, struct
C-types: basic & constructed C basic types: int, char, float, C constructed types: pointer, array, struct Memory Management Code Global variables in file (module) Local static variables in functions Dynamic
More informationOutline. Briefly review the last class Pointers and Structs Memory allocation Linked lists
Outline Briefly review the last class Pointers and Structs Memory allocation Linked lists C Structures and Memory Allocation A struct is a data structure that comprises multiple types, each known as a
More informationo Code, executable, and process o Main memory vs. virtual memory
Goals for Today s Lecture Memory Allocation Prof. David August COS 217 Behind the scenes of running a program o Code, executable, and process o Main memory vs. virtual memory Memory layout for UNIX processes,
More informationThe combination of pointers, structs, and dynamic memory allocation allow for creation of data structures
Data Structures in C C Programming and Software Tools N.C. State Department of Computer Science Data Structures in C The combination of pointers, structs, and dynamic memory allocation allow for creation
More informationSYSC 2006 C Winter 2012
SYSC 2006 C Winter 2012 Pointers and Arrays Copyright D. Bailey, Systems and Computer Engineering, Carleton University updated Sept. 21, 2011, Oct.18, 2011,Oct. 28, 2011, Feb. 25, 2011 Memory Organization
More informationActually, C provides another type of variable which allows us to do just that. These are called dynamic variables.
When a program is run, memory space is immediately reserved for the variables defined in the program. This memory space is kept by the variables until the program terminates. These variables are called
More informationC Programming Basics II
C Programming Basics II Xianyi Zeng xzeng@utep.edu Department of Mathematical Sciences The University of Texas at El Paso. September 20, 2016. Pointers and Passing by Address Upon declaring a variable,
More informationAnnouncements. Lecture 05a Header Classes. Midterm Format. Midterm Questions. More Midterm Stuff 9/19/17. Memory Management Strategy #0 (Review)
Announcements Lecture 05a Sept. 19 th, 2017 9/19/17 CS253 Fall 2017 Bruce Draper 1 Quiz #4 due today (before class) PA1/2 Grading: If something is wrong with your code, you get sympathy PA3 is due today
More informationMemory and Addresses. Pointers in C. Memory is just a sequence of byte-sized storage devices.
Memory and Addresses Memory is just a sequence of byte-sized storage devices. 1 The bytes are assigned numeric addresses, starting with zero, just like the indexing of the cells of an array. It is the
More informationFall, 2015 Prof. Jungkeun Park
Data Structures t and Algorithms Circular lists / Doubly linked lists Fall, 2015 Prof. Jungkeun Park Copyright Notice: This material is modified version of the lecture slides by Prof. Rada Mihalcea in
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationModern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi
Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Using pointers Pointers are polymorphic Pointer this Using const with pointers Stack and Heap Memory leaks and dangling pointers
More information(3-2) Basics of a Stack. Instructor - Andrew S. O Fallon CptS 122 (January 26, 2018) Washington State University
(3-2) Basics of a Stack Instructor - Andrew S. O Fallon CptS 122 (January 26, 2018) Washington State University What is a Stack? A finite sequence of nodes, where only the top node may be accessed Insertions
More informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationHowever, in C we can group related variables together into something called a struct.
CIT 593: Intro to Computer Systems Lecture #21 (11/27/12) Structs Unlike Java, C++, and to some extent Python, C is not traditionally considered an objectoriented language. That is, there is no concept
More informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More informationElementary Data Structures: Lists
Elementary Data Structures: Lists CSE 2320 Algorithms and Data Structures Based on presentation by Vassilis Athitsos University of Texas at Arlington 1 Pointers What to Review Pointers and Memory : http://cslibrary.stanford.edu/102/pointersandmemory.pdf
More informationCS 11 C track: lecture 5
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap Pointers (from last week) Address: location where data stored
More informationHeap Arrays and Linked Lists. Steven R. Bagley
Heap Arrays and Linked Lists Steven R. Bagley Recap Data is stored in variables Can be accessed by the variable name Or in an array, accessed by name and index Variables and arrays have a type Create our
More informationDynamic Data Structures. CSCI 112: Programming in C
Dynamic Data Structures CSCI 112: Programming in C 1 It s all about flexibility In the programs we ve made so far, the compiler knows at compile time exactly how much memory to allocate for each variable
More informationSolution Manual for Data Structures and Problem Solving Using C++ 2nd edition by Mark A. Weiss
Solution Manual for Data Structures and Problem Solving Using C++ 2nd edition by Mark A. Weiss Link full download: https://getbooksolutions.com/download/solutions-manual-fordata-structures-and-problem-solving-using-c-2nd-edition-by-weiss/
More informationLecture 8 Dynamic Memory Allocation
Lecture 8 Dynamic Memory Allocation CS240 1 Memory Computer programs manipulate an abstraction of the computer s memory subsystem Memory: on the hardware side 3 @ http://computer.howstuffworks.com/computer-memory.htm/printable
More informationMonday, October 30, 6pm - 8pm ME 3380 Thursday, November 2, 6pm - 8pm ME 4499
It is most beneficial to you to write this mock midterm UNDER EXAM CONDITIONS. This means: Complete the midterm in 80 minutes. Work on your own. Keep your notes and textbook closed. Attempt every question.
More information11 'e' 'x' 'e' 'm' 'p' 'l' 'i' 'f' 'i' 'e' 'd' bool equal(const unsigned char pstr[], const char *cstr) {
This document contains the questions and solutions to the CS107 midterm given in Spring 2016 by instructors Julie Zelenski and Michael Chang. This was an 80-minute exam. Midterm questions Problem 1: C-strings
More informationInstructions: Submit your answers to these questions to the Curator as OQ02 by the posted due date and time. No late submissions will be accepted.
Instructions: Submit your answers to these questions to the Curator as OQ02 by the posted due date and time. No late submissions will be accepted. For the next five questions, consider the function to
More informationDynamic Memory Allocation (and Multi-Dimensional Arrays)
Dynamic Memory Allocation (and Multi-Dimensional Arrays) Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan
More informationFall 2018 Discussion 2: September 3, 2018
CS 61C C Basics Fall 2018 Discussion 2: September 3, 2018 1 C C is syntactically similar to Java, but there are a few key differences: 1. C is function-oriented, not object-oriented; there are no objects.
More informationLinked List. April 2, 2007 Programming and Data Structure 1
Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element
More informationa) Write the signed (two s complement) binary number in decimal: b) Write the unsigned binary number in hexadecimal:
CS107 Autumn 2018 CS107 Midterm Practice Problems Cynthia Lee Problem 1: Integer Representation There is a small amount of scratch space between problems for you to write your work, but it is not necessary
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter
More informationBBM 201 DATA STRUCTURES
BBM 201 DATA STRUCTURES Lecture 10: Implementation of Linked Lists (Linked stacks and queues, Circular linked lists) 2015-2016 Fall Linked list implementation of stacks The cost of insert and delete at
More informationCprE 288 Introduction to Embedded Systems Exam 1 Review. 1
CprE 288 Introduction to Embedded Systems Exam 1 Review http://class.ece.iastate.edu/cpre288 1 Overview of Today s Lecture Announcements Exam 1 Review http://class.ece.iastate.edu/cpre288 2 Announcements
More informationCS 103 Unit 11. Linked Lists. Mark Redekopp
1 CS 103 Unit 11 Linked Lists Mark Redekopp 2 NULL Pointer Just like there was a null character in ASCII = '\0' whose ue was 0 There is a NULL pointer whose ue is 0 NULL is "keyword" you can use in C/C++
More informationChapter 17: Linked Lists
Chapter 17: Linked Lists 17.1 Introduction to the Linked List ADT Introduction to the Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures list head
More informationLecture Notes on Memory Management
Lecture Notes on Memory Management 15-122: Principles of Imperative Computation Frank Pfenning Lecture 22 November 11, 2010 1 Introduction Unlike C0 and other modern languages like Java, C#, or ML, C requires
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationCS113: Lecture 5. Topics: Pointers. Pointers and Activation Records
CS113: Lecture 5 Topics: Pointers Pointers and Activation Records 1 From Last Time: A Useless Function #include void get_age( int age ); int age; get_age( age ); printf( "Your age is: %d\n",
More informationCode Generation II. Code generation for OO languages. Object layout Dynamic dispatch. Parameter-passing mechanisms Allocating temporaries in the AR
Code Generation II Code generation for OO languages Object layout Dynamic dispatch Parameter-passing mechanisms Allocating temporaries in the AR Object Layout OO implementation = Stuff from last lecture
More informationDynamic Data Structures (II)
Lecture 23 Dynamic Data Structures (II) CptS 121 Summer 2016 Armen Abnousi Data Structure Data structures are different ways of organizing data in computer We design new data structures to make the programs
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationCpt S 122 Data Structures. Course Review Midterm Exam # 1
Cpt S 122 Data Structures Course Review Midterm Exam # 1 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 1 When: Friday (09/28) 12:10-1pm Where:
More informationLinked Lists. .. and other linked structures. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
1 Linked Lists.. and other linked structures Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Dynamic memory allocation: review typedef struct { int hitemp;
More informationCS 137 Part 5. Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors. October 25th, 2017
CS 137 Part 5 Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors October 25th, 2017 Exam Wrapper Silently answer the following questions on paper (for yourself) Do you think that the problems on
More informationCSCI-1200 Data Structures Fall 2018 Lecture 7 Templated Classes & Vector Implementation
CSCI-1200 Data Structures Fall 2018 Lecture 7 Templated Classes & Vector Implementation Announcements Lab 3 was a Frankenstein assembly of a new group exercise with part of a gdb lab. I hear many of you
More informationECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012
Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate
More informationTopics Recursive Sorting Algorithms Divide and Conquer technique An O(NlogN) Sorting Alg. using a Heap making use of the heap properties STL Sorting F
CSC212 Data Structure t Lecture 21 Recursive Sorting, Heapsort & STL Quicksort Instructor: George Wolberg Department of Computer Science City College of New York @ George Wolberg, 2016 1 Topics Recursive
More informationLecture 10 Notes Linked Lists
Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Spring 2016) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to
More informationAnnouncements. assign0 due tonight. Labs start this week. No late submissions. Very helpful for assign1
Announcements assign due tonight No late submissions Labs start this week Very helpful for assign1 Goals for Today Pointer operators Allocating memory in the heap malloc and free Arrays and pointer arithmetic
More information19-Nov CSCI 2132 Software Development Lecture 29: Linked Lists. Faculty of Computer Science, Dalhousie University Heap (Free Store)
Lecture 29 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 29: Linked Lists 19-Nov-2018 Location: Chemistry 125 Time: 12:35 13:25 Instructor: Vlado Keselj Previous
More informationJava and C CSE 351 Spring
Java and C CSE 351 Spring 2018 https://xkcd.com/801/ Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: get_mpg: pushq
More informationCS 103 Unit 11. Linked Lists. Mark Redekopp
1 CS 103 Unit 11 Linked Lists Mark Redekopp 2 NULL Pointer Just like there was a null character in ASCII = '\0' whose ue was 0 There is a NULL pointer whose ue is 0 NULL is "keyword" you can use in C/C++
More informationMemory, Arrays & Pointers
1 Memory, Arrays & Pointers Memory int main() { char c; int i,j; double x; c i j x 2 Arrays Defines a block of consecutive cells int main() { int i; int a[3]; i a[0] a[1] a[2] Arrays - the [ ] operator
More informationClass Information ANNOUCEMENTS
Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to
More informationDynamic Memory Allocation
Dynamic Memory Allocation The process of allocating memory at run time is known as dynamic memory allocation. C does not Inherently have this facility, there are four library routines known as memory management
More information04-17 Discussion Notes
04-17 Discussion Notes PIC 10B Spring 2018 1 RAII RAII is an acronym for the idiom Resource Acquisition is Initialization. What is meant by resource acquisition is initialization is that a resource should
More informationCOMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli
COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C
More informationCA341 - Comparative Programming Languages
CA341 - Comparative Programming Languages David Sinclair Dynamic Data Structures Generally we do not know how much data a program will have to process. There are 2 ways to handle this: Create a fixed data
More informationCS61, Fall 2012 Section 2 Notes
CS61, Fall 2012 Section 2 Notes (Week of 9/24-9/28) 0. Get source code for section [optional] 1: Variable Duration 2: Memory Errors Common Errors with memory and pointers Valgrind + GDB Common Memory Errors
More informationAshish Gupta, Data JUET, Guna
Categories of data structures Data structures are categories in two classes 1. Linear data structure: - organized into sequential fashion - elements are attached one after another - easy to implement because
More informationLecture Notes on Queues
Lecture Notes on Queues 15-122: Principles of Imperative Computation Frank Pfenning Lecture 9 September 25, 2012 1 Introduction In this lecture we introduce queues as a data structure and linked lists
More informationCOMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli
COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C
More informationCS113: Lecture 9. Topics: Dynamic Allocation. Dynamic Data Structures
CS113: Lecture 9 Topics: Dynamic Allocation Dynamic Data Structures 1 What s wrong with this? char *big_array( char fill ) { char a[1000]; int i; for( i = 0; i < 1000; i++ ) a[i] = fill; return a; void
More informationCOMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli
COMS W3101 Programming Language: C++ (Fall 2016) ramana@cs.columbia.edu Lecture-2 Overview of C C++ Functions Structures Pointers Design, difference with C Concepts of Object oriented Programming Concept
More informationPrinceton University Computer Science 217: Introduction to Programming Systems. Modules and Interfaces
Princeton University Computer Science 217: Introduction to Programming Systems Modules and Interfaces Barbara Liskov Turing Award winner 2008, For contributions to practical and theoretical foundations
More informationCS24 Week 3 Lecture 1
CS24 Week 3 Lecture 1 Kyle Dewey Overview Some minor C++ points ADT Review Object-oriented Programming C++ Classes Constructors Destructors More minor Points (if time) Key Minor Points const Motivation
More informationDynamic memory. EECS 211 Winter 2019
Dynamic memory EECS 211 Winter 2019 2 Initial code setup $ cd eecs211 $ curl $URL211/lec/06dynamic.tgz tar zx $ cd 06dynamic 3 Oops! I made a mistake. In C, the declaration struct circle read_circle();
More informationQ1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100
ECE 2035(A) Programming for Hardware/Software Systems Fall 2013 Exam Three November 20 th 2013 Name: Q1: /8 Q2: /30 Q3: /30 Q4: /32 Total: /100 1/10 For functional call related questions, let s assume
More information! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)
Final Exam Exercises Chapters 1-7 + 11 Write C++ code to:! Determine if a number is odd or even CS 2308 Fall 2018 Jill Seaman! Determine if a number/character is in a range - 1 to 10 (inclusive) - between
More informationECE 2400 Computer Systems Programming Fall 2018 Topic 9: Abstract Data Types
ECE 2400 Computer Systems Programming Fall 2018 Topic 9: Abstract Data Types School of Electrical and Computer Engineering Cornell University revision: 2018-10-11-00-24 1 Sequence ADTs 4 1.1. Example C-Based
More informationData Structures and Algorithms (DSA) Course 5 Lists. Iulian Năstac
Data Structures and Algorithms (DSA) Course 5 Lists Iulian Năstac Cap. Lists (recapitulation) 1. Introduction Linked lists are the best and simplest example of a dynamic data structure that uses pointers
More information(1-2) Introduction to C Data Structures & Abstract Data Types. Instructor - Andrew S. O Fallon CptS 122 (June 6, 2018) Washington State University
(1-2) Introduction to C Data Structures & Abstract Data Types Instructor - Andrew S. O Fallon CptS 122 (June 6, 2018) Washington State University What is a Data Structure? A software construct describing
More informationCS107, Lecture 9 C Generics Function Pointers
CS107, Lecture 9 C Generics Function Pointers Reading: K&R 5.11 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons Attribution 2.5 License. All
More informationCS250 Final Review Questions
CS250 Final Review Questions The following is a list of review questions that you can use to study for the final. I would first make sure that you review all previous exams and make sure you fully understand
More informationElementary Data Structures: Lists
Elementary Data Structures: Lists CSE 2320 Algorithms and Data Structures Based on presentation by Vassilis Athitsos University of Texas at Arlington 1 Pointers What to Review Pointers and Memory : http://cslibrary.stanford.edu/102/pointersandmemory.pdf
More informationAbstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1
Abstract Data Types Stack January 26, 2018 Cinda Heeren / Geoffrey Tien 1 Abstract data types and data structures An Abstract Data Type (ADT) is: A collection of data Describes what data are stored but
More informationECE 15B COMPUTER ORGANIZATION
ECE 15B COMPUTER ORGANIZATION Lecture 13 Strings, Lists & Stacks Announcements HW #3 Due next Friday, May 15 at 5:00 PM in HFH Project #2 Due May 29 at 5:00 PM Project #3 Assigned next Thursday, May 19
More informationChapter 2 (Dynamic variable (i.e. pointer), Static variable)
Chapter 2 (Dynamic variable (i.e. pointer), Static variable) August_04 A2. Identify and explain the error in the program below. [4] #include int *pptr; void fun1() { int num; num=25; pptr= #
More informationLecture 10 Notes Linked Lists
Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Summer 1 2015) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to
More informationDynamic Memory Allocation and Linked Lists
CSE 2421: Systems I Low-Level Programming and Computer Organization Dynamic Memory Allocation and Linked Lists Presentation I Read/Study: Reek Chapter 11 & 12 Gojko Babić 02-26-2017 Functions malloc and
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 5 C Memory Management Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia CS61C L05 C Structures, Memory Management (1) 2005-01-28 The
More information