Lists 4 Introduction to Lists 4 Linear Lists 4 Adding and Deleting in linear Lists 4 Linked Lists 4 Pointers in Linked Lists 4 Inserting into a Linked.

Slides:



Advertisements
Similar presentations
2000 Prentice Hall, Inc. All rights reserved. 1 Capitolo 4 - Arrays Outline 4.1Introduction 4.2Arrays 4.3Declaring Arrays 4.4Examples Using Arrays 4.5Passing.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
Copyright © 2003 Pearson Education, Inc. Slide 1.
Chapter 10 Pointers and Dynamic Arrays. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Pointers Pointer variables.
Symbol Table.
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
A pointer is the memory address of a variable. A memory address is a physical location within a system’s memory space. A pointer variable is variable used.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
Arrays and Other Data Structures 4 Introduction to Arrays 4 Bounds and Subscripts 4 Character Arrays 4 Integer Arrays 4 Floating Point Number Arrays 4.
Foundation of Computing Systems Lecture 2 Linked Lists.
Data Structures: A Pseudocode Approach with C
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Arrays Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng.
CIS 101: Computer Programming and Problem Solving Lecture 9 Usman Roshan Department of Computer Science NJIT.
Chapter 13 Hash Tables Section 13.4 CS 257 Dr. T.Y.Lin Abhishek Pandya ID
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Arrays and Other Data Structures 4 Introduction to Arrays 4 Bounds and Subscripts 4 Character Arrays 4 Integer Arrays 4 Floating Point Number Arrays 4.
1 ES 314 Advanced Programming Lec 3 Sept 8 Goals: complete discussion of pointers discuss 1-d array examples Selection sorting Insertion sorting 2-d arrays.
Chapter 4 Linked Structures. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 4-2 Chapter Objectives Describe the use of references to create.
Summary of lectures (1 to 11)
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
Arrays and Other Data Structures 4 Introduction to Arrays 4 Bounds and Subscripts 4 Integer Arrays 4 Floating Point Number Arrays 4 Lists (Linked) 4 Stacks.
Introduction to Data Structures. Data Structures A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
Introduction to Data Structures. About the document. The document is prepared by Prof. Shannon Bradshaw at Drew University. The key concepts in data structure.
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
Data Structures Week 5 Further Data Structures The story so far  We understand the notion of an abstract data type.  Saw some fundamental operations.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Dynamic Memory Allocation 9.8.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
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.
Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
Dynamic Array. An Array-Based Implementation - Summary Good things:  Fast, random access of elements  Very memory efficient, very little memory is required.
1 Linked Structures, LinkedSet References as Links Linear Linked Lists and Non-linear Structures Managing Linked Lists Data Encapsulation Separate from.
Department of Computer Science 1 Some Practice Let’s practice for the final a little bit. OK?
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Week 12 Methods for passing actual parameters to formal parameters.
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
ENEE150 – 0102 ANDREW GOFFIN More With Pointers. Importance of Pointers Dynamic Memory (relevant with malloc) Passing By Reference Pointer Arithmetic.
Data Structure and Algorithms
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
Data Structure & Algorithms
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
UNIT-II Topics to be covered Singly linked list Circular linked list
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Pointers A variable that holds an address value is called a pointer variable, or simply a pointer.  What is the data type of pointer variables? It’s not.
INTRODUCTION TO DATA STRUCTURES 1. DATA STRUCTURES A data structure is a scheme for organizing data in the memory of a computer. Some of the more commonly.
Chapter 4 Linked Structures.
© 2016 Pearson Education, Ltd. All rights reserved.
UNIT – I Linked Lists.
Linked Lists Chapter 6 Section 6.4 – 6.6
Review Deleting an Element from a Linked List Deletion involves:
Stacks and Queues.
Introduction to Data Structures
Basic notes on pointers in C
Arrays and Linked Lists
Linked Lists.
Computer Science — An Overview J. Glenn Brookshear
Chapter 17: Linked Lists.
C Programming Pointers
Data Structures & Algorithms
Presentation transcript:

Lists 4 Introduction to Lists 4 Linear Lists 4 Adding and Deleting in linear Lists 4 Linked Lists 4 Pointers in Linked Lists 4 Inserting into a Linked List 4 Deleting from a Linked List

Introduction to Lists 4 An organization’s membership list may grow and shrink in size. 4 Your phone book may also grow and shrink in size as time passes 4 We need a mechanism to store dynamic lists in the memory

Adapted for academic use from "Computer Science: An Overview" by J. Brookshear linear Lists 4 linear Lists are stored in consecutive memory locations as shown below:

Adding and Deleting in linear Lists 4 Let us consider a phone book. It can be implemented with an array containing names and phone numbers Fred David Alice Bob Carol linear List of Phone Numbers

Adding and Deleting in linear Lists 4 Deleting an entry is a two-step operation Fred David Alice Carol Deleting an entry from the linear List of Phone Numbers Fred David Alice Carol

Adding and Deleting in linear Lists 4 Adding a new entry can take place towards the end of the list Fred David Alice Carol Fred David Alice Carol Joe Adding an entry to the linear List of Phone Numbers

Linked Lists 4 If the linear list becomes large, deleting an entry in the middle of the list becomes very slow 4 It is because of the fact that we have to fill the gaps left after deleting en entry 4 If we wish to maintain the list as sorted, we have to sort it after each addition, causing additional processing overheads

Linked Lists 4 This problem can be solved if we implement the list as a linked list 4 Linked lists have entries connected with pointers 4 Deleting an entry can be implemented by re-arranging pointers 4 So we leave the entries where they are and just re-align the pointers

Pointers in Linked Lists 4 Pointers are used in C++ and other languages for pointing to other variables 4 A pointer is declared as a variables that can hold the address of another variable 4 When we declare a variable, a memory location is reserved for it by the system 4 For example 4 int my_money; 4 my_money=200;

Pointers 4 Now assume that memory location 0XFF8C is reserved by the system for the variable my_money 4 Location 0XFF8C contains the value Next, we declare a pointer variable my_key 4 int *my_key; 4 It means that my_key will hold the address of an integer variable

Pointers 4 Next, we initialize pointer my_key to point to the variable my_money 4 my_key = &my_money; 0XFF8C200 0XFF8C my_keymy_money y

Pointers 4 Conceptually, my_key points to my_money 0XFF8C200 0XFF8C my_keymy_money y

Pointers 4 Now, there are two ways to access my_money 4 We can refer to it directly 4 We can refer to it through the pointer

Pointers 4 Think about other pointers My mailing address My Home

Pointers 4 Web links are also pointers UCLA Server Computer

Inserting into a Linked List Header Fred NE XT Bob New Entry NE XT

Inserting into a Linked List Header Fred NE XT Bob NE XT

Deleting from a Linked List Header Bob NE XT Alice NE XT Fred NE XT

Deleting from a Linked List Header Bob NE XT Alice NE XT Fred NE XT