Linked List (II) CGS 3460, Lecture 37 Apr 12, 2006 Hen-I Yang.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
Linked Lists.
Chapter 12 Lists and Iterators. List Its an abstract concept not a vector, array, or linked structure. Those are implementations of a List. A list is a.
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Compilation and Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
CSE 303 Lecture 16 Multi-file (larger) programs
CS1061: C Programming Lecture 21: Dynamic Memory Allocation and Variations on struct A. O’Riordan, 2004, 2007 updated.
1 1 Lecture 4 Structure – Array, Records and Alignment Memory- How to allocate memory to speed up operation Structure – Array, Records and Alignment Memory-
Data Structures Data Structures Topic #8. Today’s Agenda Continue Discussing Table Abstractions But, this time, let’s talk about them in terms of new.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 17 - The Preprocessor Outline 17.1Introduction 17.2The #include Preprocessor Directive 17.3The.
Rossella Lau Lecture 3, DCO20105, Semester A, DCO Data structures and algorithms  Lecture 3: Basics of Linked List  C++ pointer revision.
1 CS 201 Dynamic Data Structures Debzani Deb. 2 Run time memory layout When a program is loaded into memory, it is organized into four areas of memory.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
C FAQ’S Collected from the students who attended technical round in TCS recruitment.
 2007 Pearson Education, Inc. All rights reserved C Preprocessor.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 19 - The Preprocessor Outline 19.1 Introduction 19.2 The #include Preprocessor Directive 19.3.
The preprocessor and the compilation process COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
CGS 3460 Pointer n To hold the location of another variable n Declaration: la type and a name with an asterisk lE.g. int *ptr; n Assigning a value lptr.
17. ADVANCED USES OF POINTERS. Dynamic Storage Allocation Many programs require dynamic storage allocation: the ability to allocate storage as needed.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
CMSC 2021 CMSC 202 Computer Science II for Majors Fall 2002 Mr. Frey (0101 – 0104) Mr. Raouf (0201 – 0204)
C Hints and Tips The preprocessor and other fun toys.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
SQL in a Programming Environment CIS 4301 Lecture Notes Lecture /11/2006.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessing Lecture 12 April 7, 2005.
Iteration Statements CGS 3460, Lecture 17 Feb 17, 2006 Hen-I Yang.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
CMSC 2021 CMSC 202 Computer Science II for Majors Spring 2003 Mr. Frey (0101 – 0104) Mr. Raouf (0201 – 0204)
Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.
Summary CGS 3460, Lecture 43 April 26, 2006 Hen-I Yang.
Lecture-3 Functions and Recursion. C Preprocessor Includes header files like stdio.h Expands macros defined Handles conditional compilations PreprocessorProcessor.
THE PREPROCESSOR
The Preprocessor Directives Introduction Preprocessing – Occurs before program compiled Inclusion of external files Definition of symbolic constants.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee C Language Part 5.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 11 : September 18.
1 Object-Oriented Programming -- Using C++ Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
MORE POINTERS Plus: Memory Allocation Heap versus Stack.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
1 Linked List. 2 List A list refers to a sequence of data items  Example: An array The array index is used for accessing and manipulation of array elements.
13 C Preprocessor.
Function: Declaration
5.13 Recursion Recursive functions Functions that call themselves
UNIT – I Linked Lists.
Data Structure Interview Question and Answers
ECE Application Programming
Data Structure and Algorithms
Chapter 13 - The Preprocessor
CGS 3460, Lecture 41 Apr 21, 2006 Hen-I Yang
ENEE150 Discussion 13 Section 0101 Adam Wang.
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Learning Objectives What else in C++ Bitwise operator
Review & Lab assignments
Recursive Linked Lists
Linked List.
Linked Lists Adapted from Dr. Mary Eberlein, UT Austin.
C Preprocessor Seema Chandak.
C Programming Pointers
Recursive Linked Lists
CS148 Introduction to Programming II
CSE 303 Concepts and Tools for Software Development
Presentation transcript:

Linked List (II) CGS 3460, Lecture 37 Apr 12, 2006 Hen-I Yang

Previously… Union and Enum Linked list

Agenda Homework 6 (Finally) Linked List Introduction to preprocessor

Homework 6 2 problems Problem 1: Iterative and Recursive Functions  Convert Decimal Numbers to Binary Representations Problem 2: Linked List  Contact List Homework 6 description Needed.h and.c files.h.c Make sure you check back later today.

Quiz 5 and the Lecture on April 14 Quiz 5 has 3 questions, less questions in each set The material is much harder than any of the previous ones, make sure you spend enough time studying for this Instead of the normal 15 – 20 minutes, I will allot 40 minutes for this quiz and you are allowed to turn in early For the remaining 10 minutes, I will hold a tutorial type Q&A session for any questions related to the materials we’ve covered so far.

Linked List Operations  Start a list  Create a node  Insert  Search  Query  Print

Build a Linked List (I) Build a structure representing a node struct athlete { float speed; struct athlete * next; }; Initialize the node struct athelete *first = NULL;

Build a linked list: Create a node allocate memory for the node storing data into the node; insert the node into the list struct athlete *new_player; new_player = malloc(sizeof(struct athelete)); (*new_player).speed = 9.90; new_player  next = NULL; first = new_player;

Insert a node: insert in the front new_player = malloc(sizeof(struct athelete)); new_player  speed = 9.85; new_player  next = first  next; first = new_player;

Insert a node: insert at the end new_player = malloc(sizeof(struct athelete)); new_player  speed = 10.10; new_player  next = NULL; (first  next)  next = new_player;

Search and Delete Search: for (p = first; p != NULL; p = p  next) { …. } Delete (almost reverse of insertion):  locating the node to be deleted (see search a linked list)  altering the previous node to bypass the deleted node  calling free to reclaim the space occupied by the deleted node What to do to print everything out? (exercise)

Insert a node: insert in between new_player = malloc(sizeof(struct athelete)); new_player  speed = 10.00; new_player  next = NULL; struct athelete * q; for (p = first; p != NULL; p = p  next) { if (p  speed > 10.00) { new_player  next = q  next; q  next = new_player; } q = p; } (first  next)  next = new_player;

Pointer to Functions Pass as an argument in other function Exception handling More flexible (and abstract) programming int (*f) (int);  (a function declaration, not definition) Example:  void qsort(void * base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));

What’s next? Preprocessors  Directives (#include, #define) are handled by preprocessor  Preprocessing is handled prior to compilation C program Modified C prog Object Code  Powerful, but can be hard to debug  Recommended to be used carefully and moderately compilerpreprocessor

Preprocssor Directives Macro definition  #define, #undef File inclusion  #include Conditional Compilation  #if, #ifdef, #ifndef, #elseif, #else Others  #error, #line, #pragma

Q&A It’s your chance to ask the questions.

Summary Linked List Introduction to Preprocessor

Before you go Homework 5 late submission deadline tomorrow at 11:59 pm Make sure you spend enough time study for this quiz on pointers. Pointer is one of the most difficult concepts in C language. Although there are less questions and more time, you will need to understand the concept to do well in this quiz. Ask TA if you have any questions about pointers.