Midterm Review. CS 211 Fall 2018

Similar documents
The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures

These problems are provided to you as a guide for practice. The questions cover important concepts covered in class.

ECE 2400 Computer Systems Programming Fall 2018 Topic 7: Concrete Data Types

11 'e' 'x' 'e' 'm' 'p' 'l' 'i' 'f' 'i' 'e' 'd' bool equal(const unsigned char pstr[], const char *cstr) {

ECE264 Fall 2013 Exam 3, November 20, 2013

Big- (O): c.) binary search O(logn)

ECE264 Spring 2013 Final Exam, April 30, 2013

Heap Arrays and Linked Lists. Steven R. Bagley

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

ECE 2400 Computer Systems Programming Fall 2017 Topic 7: C Lists and Vectors

Heap Arrays. Steven R. Bagley

CS 11 C track: lecture 6

Dynamic Memory Management. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

CIS 190: C/C++ Programming. Linked Lists

CS61C Machine Structures. Lecture 4 C Structs & Memory Management. 9/5/2007 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

CMSC 341 Lecture 7 Lists

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?

Actually, C provides another type of variable which allows us to do just that. These are called dynamic variables.

CS 222: Pointers and Manual Memory Management

BBM 201 DATA STRUCTURES

Data Structures and Algorithms (DSA) Course 5 Lists. Iulian Năstac

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

Arrays and Pointers (part 1)

(2-1) Data Structures & The Basics of a Linked List I. Instructor - Andrew S. O Fallon CptS 122 (August 27, 2018) Washington State University

C Programming, Autumn 2013, Exercises for the Second Week

CS 61C: Great Ideas in Computer Architecture C Pointers. Instructors: Vladimir Stojanovic & Nicholas Weaver

Queues. October 20, 2017 Hassan Khosravi / Geoffrey Tien 1

MIDTERM EXAM. CS 217 October 28, Name: Precept: Honor Code: Score: Problem Score Max

Midterm Review (overview of fall 2005 midterm)" Jennifer Rexford!

malloc(), calloc(), realloc(), and free()

Lecture 8 Dynamic Memory Allocation

Algorithms, Data Structures, and Problem Solving

Linked List. April 2, 2007 Programming and Data Structure 1

Understanding Pointers

Week 9 Part 1. Kyle Dewey. Tuesday, August 28, 12

Memory Management. CS31 Pascal Van Hentenryck CS031. Lecture 19 1

(6-1) Basics of a Queue. Instructor - Andrew S. O Fallon CptS 122 (September 26, 2018) Washington State University

Chapter 2 (Dynamic variable (i.e. pointer), Static variable)

(More) Fun with Pointers and Linked Lists! CS 16: Solving Problems with Computers I Lecture #17

FORM 2 (Please put your name and form # on the scantron!!!!)

Low-Level C Programming. Memory map Pointers Arrays Structures

In Java we have the keyword null, which is the value of an uninitialized reference type

Linked Lists. .. and other linked structures. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

CS349/SE382 A1 C Programming Tutorial

CS 61c: Great Ideas in Computer Architecture

COMP 524 Spring 2018 Midterm Thursday, March 1

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100

Dynamic Data Structures. CSCI 112: Programming in C

Lecture 7: Data Structures. EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology

CS61, Fall 2012 Section 2 Notes

CA341 - Comparative Programming Languages

Announcements. assign0 due tonight. Labs start this week. No late submissions. Very helpful for assign1

More about BOOLEAN issues

September 10,

Chapter 6. Data Structure. /* start contains the address of the first node */ start = &elephant1; print_elephants( start ); return EXIT_SUCCESS;

Monday, October 30, 6pm - 8pm ME 3380 Thursday, November 2, 6pm - 8pm ME 4499

Dynamic Data Structures (II)

Name: uteid: 1. CS439H: Fall 2011 Midterm 1

C Programming Basics II

CS 241 Data Organization Binary Trees

ENEE 150: Intermediate Programming Concepts for Engineers Spring 2018 Handout #27. Midterm #2 Review

Dynamic Memory Allocation and Linked Lists

CS3157: Advanced Programming. Announcement

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

Midterm Sample Questions. a) What evaluates to FALSE in C? What evaluates to TRUE?

Cpt S 122 Data Structures. Data Structures

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

Elementary Data Structures: Part 1: Arrays, Lists. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington

Memory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)

COMSW Introduction to Computer Programming in C

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

Structures and Pointers

a) Write the signed (two s complement) binary number in decimal: b) Write the unsigned binary number in hexadecimal:

ANITA S SUPER AWESOME RECITATION SLIDES

How about them A s!! Go Oaktown!! CS61C - Machine Structures. Lecture 4 C Structures Memory Management Dan Garcia.

Lists, Stacks and Queues in C. CHAN Hou Pong, Ken CSCI2100A Data Structures Tutorial 4

EECE.2160: ECE Application Programming Fall 2017 Exam 3 December 16, 2017

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Name: uteid: 1. CS439H: Fall 2011 Midterm 1

Data Representation and Storage

CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018

Elementary Data Structures: Lists

CS 61C: Great Ideas in Computer Architecture C Memory Management, Usage Models

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

CS 11 C track: lecture 5

COMP-202: Foundations of Programming. Lecture 13: Recursion Sandeep Manjanna, Summer 2015

Introduction to Data Structures. Systems Programming

Lecture Notes CPSC 122 (Fall 2014) Today Quiz 7 Doubly Linked Lists (Unsorted) List ADT Assignments Program 8 and Reading 6 out S.

CS24 Week 2 Lecture 1

CS61C : Machine Structures

Data Representation and Storage. Some definitions (in C)

Memory Allocation in C C Programming and Software Tools. N.C. State Department of Computer Science

DO NOT OPEN UNTIL INSTRUCTED

C Programming Language: C ADTs, 2d Dynamic Allocation. Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CS 137 Part 5. Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors. October 25th, 2017

Data Structure Series

COMP 2355 Introduction to Systems Programming

EE 312 Fall 2017 Midterm 1 October 12, 2017

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

Transcription:

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 is a class right after ours If you arrive late, you lose time (been shown to have negative impact on your final score) This is an Open Brain Exam No notes, texts, calculators, friends, etc.

About 4 Questions You will be writing C code More emphasis on Sematics (meaning) than Syntax But proper syntax is still important and expected Think about important code pieces from Projects and Labs

C Pointers is the Main Topic Dynamic Arrays Linked Lists Use of malloc() is expected/required! Use of C Pointers in C structs with typedefs Assume variables are declared in main( ) Assume variables are passed to functions Pass-by-value and pass-by-reference knowledge is expected Assume manipulation occurs in these functions

Dynamic Arrays typedef struct dynarrstruct { int* int int dynarr; dynarray; allocated; inuse; Operations initialize insert value (and growing array) access and use of structure

Dynamic Arrays declared in main( ) main( ) { dynarr arr1; /* create instance on the stack */ init ( &arr1); /*call initialization function */ addvalue ( &arr1, val ); /* insert value */ if ( isempty( arr1 ) == TRUE ) /* use/access of array */

Dynamic Array instance initialized to be able to store 10 values: void init ( dynarr & arr) { /* Note: Pass-by-Reference Param */ arr->allocated = 10; arr->dynarray = ( int* ) malloc ( sizeof(int) * arr->allocated); arr->inuse = 0;

Value added to Dynamic Array instance : void addvalue ( dynarr & arr, int val) { /* Note: Pass-by-Reference param */ if ( arr->inuse >= arr->allocated ) { int* tmp = arr->dynarray arr->dynarray = ( int* ) malloc ( sizeof(int) * (arr->allocated * 2) ); int a; for ( a = 0 ; a < arr->inuse ; a++) arr->dynarray[a] = tmp[a]; free (tmp); arr->allocated = arr->allocated * 2; arr->dynarray[arr->inuse] = val; arr->inuse = arr->inuse + 1;

Dynamic Array other functions : int isempty ( dynarr arr ) { if ( arr.inuse == 0) /* using. since pass-by-value param */ return TRUE; else return FALSE; int getlastvalue( dynarr arr ) { if (isempty (arr) == TRUE ) return -999; /* some error value */ else return arr.dynarr [ arr.inuse 1 ] ;

Dynamic Array other functions : int removelastvalue( dynarr* arr ) { /* NOTE: Pass-by-Reference param */ if (isempty (*arr) == TRUE ) return FALSE; /* some error value */ else arr->inuse = arr->inuse 1 ; int getnthvalue( dynarr arr, int n) { /* NOTE: Pass-by-Value param */ if ( (isempty (arr) == TRUE ) (n >= arr.inuse ) ) return -999; /* some error value */ else return arr.dynarr [ arr.inuse 1 ];

Linked List typedef struct nodestruct { int elem; struct nodestruct* node; Operations initialize insert value access and use of list remove value next;

Linked List declared in main( ) main( ) { node* head; /* create pointer on the stack */ /*initialize list to empty multiple approaches */ init ( &head); head = init2 ( ); head = NULL; addtolist ( &head, val ); /* pass-by-reference: modifying list */ removevaluefromlist ( &head, val ); removefirstnode (&head ); val = getnthvalue ( head, position ); /* pass-by-value: accessing list */ length = listlength ( head);

Linked List initialization void init (node** hd) { *hd = NULL; node* init2 ( ) { return NULL;

Linked List add value See Code on Lab Pages for examples (lab6.c has them all) malloc ( ) statement node* tmp = (node*) malloc ( sizeof (node) ); Common Insertion Points Insert at the beginning of the list Insert at the end of the list Insert in increasing order

void insertinorder (node** hd, int val) { node* curr = *hd; node* prev = NULL; while ((curr!= NULL) && (curr->elem < val)) { /* set curr to node in the list that is >= val */ prev = curr; /* set prev to node just before curr */ curr = curr->next; node* ptr = (node*) malloc (sizeof(node)); /* create the node to add into the list */ ptr->elem = val; ptr->next = curr; if (prev == NULL) /* if prev is null, insert at the front of the list */ *hd = ptr; else prev->next = ptr; /* otherwise insert right after prev */

Linked List Usage determining length int listlength (node* hd) { int length = 0; while (hd!= NULL) { length++; hd = hd->next; return length;

Linked List Usage print values in the list int show (node* hd) { while (hd!= NULL) { printf ( %d,, hd->elem ); hd = hd->next; printf ( \n );

Linked List Usage get the Nth vlaue int show (node* hd, int n) { int position = 0; while (hd!= NULL) { if ( position == n ) return hd->elem; position++; hd = hd->next; return -999; /* some error value because list is too short */