ENEE150 Final Exam Review

Similar documents
Stacks. Linear data structures

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Linked Lists Linked Lists, Queues, and Stacks

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

C++ Programming Language

St S a t ck a ck nd Qu Q eue 1

Introduction to Data Structures

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

PES Institute of Technology-BSC QUESTION BANK

List, Stack and Queue. Tom Chao Zhou CSC2100B Data Structures Tutorial 3

DATA STRUCTURES USING C

Common Data Structures

Short Notes on Dynamic Memory Allocation, Pointer and Data Structure

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct

10CS35: Data Structures Using C

Data Structures and Data Manipulation

7.1 Our Current Model

CmpSci 187: Programming with Data Structures Spring 2015

Analysis of a Search Algorithm

Illustration 1: Diagram of program function and data flow

Chapter 3: Restricted Structures Page 1

Last not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!

Introduction to Java

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

Data Structures, Practice Homework 2, with Solutions (not to be handed in)

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

The C Programming Language course syllabus associate level

C++ INTERVIEW QUESTIONS

Abstract Data Types. Chapter 2

Data Structure with C

This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues Goodrich, Tamassia

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

1 Abstract Data Types Information Hiding

Universidad Carlos III de Madrid

C Compiler Targeting the Java Virtual Machine

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Client-server Sockets

Cpt S 223. School of EECS, WSU

Data Structures and Algorithms Stacks and Queues

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Data Structures Using C++ 2E. Chapter 5 Linked Lists

CS 2412 Data Structures. Chapter 3 Queues

Course: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1

Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets

C Dynamic Data Structures. University of Texas at Austin CS310H - Computer Organization Spring 2010 Don Fussell

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

Object Oriented Software Design II

C Interview Questions

C++FA 5.1 PRACTICE MID-TERM EXAM

Data Structures and Algorithms

What is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2)

Passing 1D arrays to functions.

Linear ADTs. Restricted Lists. Stacks, Queues. ES 103: Data Structures and Algorithms 2012 Instructor Dr Atul Gupta

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Glossary of Object Oriented Terms

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

Data Structures Using C++ 2E. Chapter 5 Linked Lists

System Calls and Standard I/O

Algorithms and Data Structures Exercise for the Final Exam (17 June 2014) Stack, Queue, Lists, Trees, Heap

Unit Write iterative and recursive C functions to find the greatest common divisor of two integers. [6]

Tutorial on C Language Programming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.

Semantic Analysis: Types and Type Checking

CS 2412 Data Structures. Chapter 2 Stacks and recursion

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

Lecture 12 Doubly Linked Lists (with Recursion)

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Basic Data Structures and Algorithms

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Introduction to Programming

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

STACKS,QUEUES, AND LINKED LISTS

Sources: On the Web: Slides will be available on:

Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson

How To Write Portable Programs In C

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

Module 816. File Management in C. M. Campbell 1993 Deakin University

13 Classes & Objects with Constructors/Destructors

1. Define: (a) Variable, (b) Constant, (c) Type, (d) Enumerated Type, (e) Identifier.

Programming languages C

Data Structures. Level 6 C Module Descriptor

7th Marathon of Parallel Programming WSCAD-SSC/SBAC-PAD-2012

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

Answers to Review Questions Chapter 7

Chapter 5. Recursion. Data Structures and Algorithms in Java

Chapter 2: Elements of Java

22c:31 Algorithms. Ch3: Data Structures. Hantao Zhang Computer Science Department

Lecture 11 Array of Linked Lists

Transcription:

ENEE150 Final Exam Review Topics: Pointers -- pointer definitions & initialization -- call-by-reference and Call-by-value -- pointer with arrays -- NULL pointer, void pointer, and pointer to pointer Strings -- string defined with pointer -- string manipulation functions: string searching, string comparison, string copy, string concatenation, string tokenizing Dynamic memory allocation (malloc, free, calloc, realloc) Structure -- structure template and variable declaration -- typedef -- Access members (using dot or arrow) -- nested structures Linked List -- understand pointer to pointer sptr -- understand how to insert/delete a node, and display the list. -- stack: push and pop (LIFO) -- queue: enqueue and dequeue (FIFO) ADT -- definition of ADT -- be able to give the abstract view of an ADT given specifications (.h file) -- understand concept of constructor and deconstructor Review Problems: (Please review all the practice problems in the midterm review sheet) 1. What is displayed by the following program segment if all variables are of type int and the input data is the data shown? st = scanf("%d%d%d", &n, &m, &p); printf("n=%d m=%d st=%d\n", n, m, st); Input data: 10 12 hello 2. What will be the output of the program? #include<stdio.h> 1

int x=30, *y, *z; y=&x; /* Assume address of x is 500 and integer is 4 bytes */ z=y; *y++ = *z++; x++; printf("x=%d, y=%d, z=%d\n", x, y, z); 3. Given the following declarations typedef struct char name[20]; int id; double salary; emprec_t;... emprec_t emp1, emp2; char ch1; int flag1, flag2; (1) Which of the following could not be a valid statement? a. emprec_t.id = 87654; b. emp1.salary *= 1.05; c. ch1 = emp2.name[0]; d. printf("%.2f", emp1.salary); e. All of the above are valid. (2) Which of the following could not be a valid use of the variables shown? You may assume that print_employee is a user-defined function. a. emp2 = emp1; b. flag1 = emp1 == emp2; c. flag2 = emp1.id == emp2.id; d. print_employee(emp1); e. All of the above are valid. 4. Given: typedef struct node_s double data; struct node_s *leftp, *rightp; node_t; 2

The name node_t is equivalent to. a. node_s * b. node_s c. struct node_s * d. struct node_s 5. Define a type named node_t that is appropriate for one node of a linked list in which each node's data consists of an integer and a 6-element array of type double. 6. If a linked list contains three nodes with values "him", "her", and "its", and start is a pointer to the list head, assume the following data structure, typedef struct node char pronoun[20]; struct node *next; Node; Node *np, *mp; What is the effect of each of the following statements? Describe how many nodes in the list and what the values of each node are. Each case is independent of each other. (1) np = start -> next; strcpy(np -> pronoun, "she"); (2) mp = start -> next; np = mp -> next; mp -> next = np -> next; free (np); (3) np = start; start = (Node *) malloc (sizeof (Node)); strcpy( start -> pronoun, "his"); start -> next = np; 7. Write a function that merges two linked lists. Assume the following data structure for the list: typedef struct node int num; struct node *next; NODE; 8. Give the output for the program below: #include <stdio.h> #include <stdlib.h> #define MAX 3 void init(int a[]) a[0] = 23; 3

a[1] = 56; a[2] = 17; void increase(int *p) p++; printf("%d\n", p[0]); int numbers[max], *other; init(numbers); other = (int*) malloc(max*sizeof(int)); init(other); increase(numbers); printf("%d\n", numbers[0]); other++; printf("%d\n", other[0]); 9. Write a function prototype for a function sum_n_avg that has three type double input parameters and two output parameters. n1 n2 n3 sum_n_avg sump avgp 10. Given the definition typedef struct stack_node_s char element; struct stack_node_s *next; stack_node_t; Draw the stack resulting from execution of the following code segments step by step. Assume you are working with a linked list implementation of a stack of individual characters. stack_node_t *sptr = NULL; push(&sptr, a ); push(&sptr, b ); pop(&sptr); push(&sptr, c ); 4

11. Given the definition in 10, write a push function to insert a character to the top of the stack (i.e. to the beginning of the linked list) void push (stack_node_t **sp, char c); 12. What will be the output of the following program if the starting address of x is 100, and the starting address of array a is 200? #include <stdio.h> int *p, x; int a[5]=100,200,300,400,500; int *p2; p=null; x=500; p=&x; printf("1) %d %d %u %u\n",x,*p,p,&x); p2=a; *(p2+1)=*p; *p= *p2 + *(p2+2); p2++; printf("2) %d %d %d %u\n",x,*p,*p2,p2); 13. What will be the output of the following program? #include<stdio.h> char *a[4]= "MC", "C Programming", "Data", "Structure"; char *p; int i; for (i=0;i <4;i++) printf("%s \n", a[i]); p = a[0]; printf("%c \n", *p); p=p+1; printf("%c \n", *p); p=&a[2][0]; printf("%c \n", *p); p=p+1; printf("%c \n", *p); 5

13. What will be the output of the following program? #include<stdio.h> struct course int courseno; char coursename[25]; ; struct course c[] = 102, "Java", 103, "PHP", 104, "DotNet" ; printf("%d ", c[1].courseno); printf("%s\n",(c+2)->coursename); 6

Review Problem Solution 1. n=10 m=12 st=2 2. x=31, y=504, z=504 3.1) a 2) b 4. d 5. typedef struct node_s int num; double list[6]; struct node_s *restp; node_t; 6 (1) It replaces "her" by "she". So we still have three nodes with values "him", "she", and "its". (2) The third node in the list is deleted. We only have two nodes with values "him" and "her". (3) A new node with value "his" is inserted in the beginning of the list. We will have four nodes with values "his", "him", "her", and "its". 7 void merge(node **first, NODE **second) NODE *end,*start; /* Find the current pointer to two lists */ end = *first; start = *second; /* Find tail of the first list */ while ( end -> next!= NULL ) end = end ->next; /* Tail of the first list points to the head of the second list */ end -> next = start; 8. Output of the program is: 56 23 56 9. void sum_n_avg (double n1, double n2, double n3, double *sump, double *avgp); 7

10. b c a a a a 11. void push (stack_node_t **sp, char c) stack_node_t *newptr; newptr =(stack_node_t *) malloc(sizeof(stack_node_t)); newptr -> element = c; newptr -> next = *sp; *sp = newptr; 12. 1) 500 500 100 100 2) 400 400 500 204 13. MC C Programming Data Structure M C D a 14. 103 DotNet 8