Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.

Slides:



Advertisements
Similar presentations
TK1924 Program Design & Problem Solving Session 2011/2012
Advertisements

DATA STRUCTURES USING C++ Chapter 5
Linked Lists Linked Lists Representation Traversing a Linked List
Data Structures Using C++
CHP-5 LinkedList.
M180: Data Structures & Algorithms in Java
Review Learn about linked lists
Data Structures: A Pseudocode Approach with C
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are crated using the class definition. Programming techniques.
Data Structures & Algorithms
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
Linked Lists Dr. Youssef Harrath
Data Structures Using C++ 2E Chapter 11 Binary Trees and B-Trees.
Chapter 3: Arrays, Linked Lists, and Recursion
Data Structures Using C++ 2E
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Data Structures Using Java1 Chapter 4 Linked Lists.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Linked Lists part 2 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
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.
Pointer and Array Lists Chapter 3, Summary CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 17: Linked Lists.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Linked List Chapter Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.
Data Structures Using C++1 Chapter 5 Linked Lists.
1. Circular Linked List In a circular linked list, the last node contains a pointer to the first node of the list. In a circular linked list,
Ceng-112 Data Structures ISerap ATAY, Ph. D. 1 Chapter 3 – Part 2 Linear Lists.
CHAPTER 17 LINKED LISTS. In this chapter, you will:  Learn about linked lists  Become aware of the basic properties of linked lists  Explore the insertion.
Data Structures Using C++ 2E Chapter 11 Binary Trees.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
Department of Computer Science 1 Some Practice Let’s practice for the final a little bit. OK?
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
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:
Linked List Containers. Useful Linked List Add-Ons Are there new variables/changes to the lists as they have been defined that could make our jobs as.
Linked List. LINKED LIST Link is collection of similar type of elements. There are two ways of maintaining a list in memory. The first way is store the.
Data Structure & Algorithms
1 CS 132 Spring 2008 Chapter 5 Linked Lists p
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
  A linked list is a collection of components called nodes  Every node (except the last one) contains the address of the next node  The address of.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
List data structure This is a new data structure. The List data structure is among the most generic of data structures. In daily life, we use shopping.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
CPSC 252 Linked Lists III Page 1 Variations on Singly Linked Lists Inserting or deleting at the front of a list is different from at any other point in.
Chapter 16: Linked Lists.
Linked List ADT used to store information in a list
Lecture 6 of Computer Science II
C++ Programming:. Program Design Including
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists (cont) [Chapter 4; Chapter 6, pp ]
Data Structure By Amee Trivedi.
UNIT – I Linked Lists.
Review Deleting an Element from a Linked List Deletion involves:
Data Structure and Algorithms
UNIT-3 LINKED LIST.
Linked lists.
Sequences 9/18/ :20 PM C201: Linked List.
Data Structures Using C++ 2E
Chapter 18: Linked Lists.
Doubly Linked Lists or Two-way Linked Lists
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
Chapter 17: Linked Lists.
Data Structures & Algorithms
CS148 Introduction to Programming II
Linked lists.
Presentation transcript:

Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists

Department of Computer Science 2 Data Structures Using C++ 2E Objectives  Learn about linked lists  Become aware of the basic properties of linked lists  Explore the insertion and deletion operations on linked lists  Discover how to build and manipulate a linked list

Department of Computer Science 3 Data Structures Using C++ 2E Objectives (cont’d.)  Learn how to construct a doubly linked list  Discover how to use the STL container list  Learn about linked lists with header and trailer nodes  Become aware of circular linked lists

Department of Computer Science 4 Linked Lists  Collection of components (nodes)  Every node (except last)  Contains address of the next node  Node components  Data: stores relevant information  Link: stores address Data Structures Using C++ 2E FIGURE 5-1 Structure of a node

Department of Computer Science 5 Data Structures Using C++ 2E Linked Lists (cont’d.)  Head (first)  Address of the first node in the list  Arrow points to node address  Stored in node  Down arrow in last node indicates NULL link field FIGURE 5-2 Linked list FIGURE 5-3 Linked list and values of the links

Department of Computer Science 6 Data Structures Using C++ 2E Linked Lists (cont’d.)  Two node components  Declared as a class or struct  Data type depends on specific application  Link component: pointer  Data type of pointer variable: node type itself

Department of Computer Science 7 Data Structures Using C++ 2E Linked Lists: Some Properties  Head stores address of first node  Info stores information  Link stores address of next node  Assume info type int FIGURE 5-4 Linked list with four nodes TABLE 5-1 Values of head and some of the nodes of the linked list in Figure 5-4

Department of Computer Science 8 Data Structures Using C++ 2E Linked Lists: Some Properties (cont’d.)  Pointer current : same type as pointer head  current = head;  Copies value of head into current  current = current->link;  Copies value of current->link ( 2800) into current FIGURE 5-5 List after the statement current = current->link; executes

Department of Computer Science Data Structures Using C++ 2E9 Linked Lists: Some Properties (cont’d.) TABLE 5-2 Values of current, head, and some of the nodes of the linked list in Figure 5-5

Department of Computer Science 10 Traversing a Linked List  Basic linked list operations  Search list to determine if particular item is in the list  Insert item in list  Delete item from list  These operations require list traversal  Given pointer to list first node, we must step through list nodes Data Structures Using C++ 2E

Department of Computer Science 11 Traversing a Linked List (cont’d.)  Suppose head points to a linked list of numbers  Code outputting data stored in each node Data Structures Using C++ 2E

Department of Computer Science 12 Data Structures Using C++ 2E12 Item Insertion and Deletion  Generic definition of a node on page 270 TABLE 5-3 Inserting a node in a linked list

Department of Computer Science 13 Data Structures Using C++ 2E Item Insertion and Deletion (cont’d.)  Sequence of statements to insert node  Very important  Use only one pointer ( p ) to adjust links of the nodes  Using two pointers  Can simplify insertion code somewhat

Department of Computer Science 14 Data Structures Using C++ 2E14 Item Insertion and Deletion (cont’d.)  Memory still occupied by node after deletion  Memory is inaccessible  Deallocate memory using a pointer to this node FIGURE 5-10 List after the statement p->link = p->link->link; executes

Department of Computer Science 15 Data Structures Using C++ 2E Building a Linked List  If linked list data unsorted  Linked list unsorted  Ways to build linked list  Forward  New node always inserted at end of the linked list  See example on page 274  See function buildListForward on page 277  Backward  New node always inserted at the beginning of the list  See example on page 277  See function buildListBackward on page 278

Department of Computer Science 16 Visual Studio Example buildListForward

Department of Computer Science 17 Text

Department of Computer Science 18 Text

Department of Computer Science 19 Text

Department of Computer Science 20 Text

Department of Computer Science 21 Text

Department of Computer Science 22 Text

Department of Computer Science 23 Text

Department of Computer Science 24 Text

Department of Computer Science 25 Text

Department of Computer Science 26 Text

Department of Computer Science 27 Text

Department of Computer Science 28 Text

Department of Computer Science 29 Text