Unit 1 - Introducing Abstract Data Type (ADT) Part 3 – Slides 24 to end.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Linked Lists.
Linked Lists Chapter 4.
DATA STRUCTURES USING C++ Chapter 5
Chapter 24 Lists, Stacks, and Queues
Chapter 17 Linked List Saurav Karmakar Spring 2007.
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Linked Lists
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
CS Data Structures Chapter 8 Lists Mehmet H Gunes
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
1 Data Structures Data Structures Topic #2. 2 Today’s Agenda Data Abstraction –Given what we talked about last time, we need to step through an example.
Data Structures Topic #3. Today’s Agenda Ordered List ADTs –What are they –Discuss two different interpretations of an “ordered list” –Are manipulated.
Chapter 8 Lists. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 8-2 Chapter Objectives Examine list processing and various ordering techniques.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
Chapter 3: Arrays, Linked Lists, and Recursion
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
Chapter 4 Linked Structures – Stacks Modified. Chapter Scope Object references as links Linked vs. array-based structures Managing linked lists Linked.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
Chapter 8 Lists. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Examine list processing and various ordering techniques.
C++ Classes and Data Structures Jeffrey S. Childs
Searching: Binary Trees and Hash Tables CHAPTER 12 6/4/15 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education,
Data Structures Using Java1 Chapter 4 Linked Lists.
Chapter 1 Data Structures and Algorithms. Primary Goals Present commonly used data structures Present commonly used data structures Introduce the idea.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
Linked List. Iterators Operation to find a link, deleting, and inserting before or after a specified link, also involve searching through the list to.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
CSC Data Structures, Fall, 2008 Monday, September 29, end of week 5, Generic Functions and Classes in C++
Winter 2006CISC121 - Prof. McLeod1 Stuff Deadline for assn 3 extended to Monday, the 13 th. Please note that the testing class for assn 3 has changed.
Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken.
Queues. Like Stacks, Queues are a special type of List for storing collections of entities. Stacks are Lists where insertions (pushes) and deletions (pops)
Data Structures Using C++1 Chapter 5 Linked Lists.
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Page 1 – Spring 2010Steffen Vissing Andersen Software Development with UML and Java 2 SDJ I2, Spring 2010 Agenda – Week 8 Linked List (a reference based.
Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley CHAPTER 4 Linked.
Week 4 - Friday.  What did we talk about last time?  Continued doubly linked list implementation  Linked lists with iterators.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
Doubly Linked List Exercises Sometimes it is useful to have a linked list with pointers to both the next and previous nodes. This is called a doubly linked.
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.
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Unit 1 - Introducing Abstract Data Type (ADT) Part 1.
UNIT-II Topics to be covered Singly linked list Circular linked list
LINKED LISTS.
Unit 1 - Introducing Abstract Data Type (ADT) Part 3 – Slides 1 to 11.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Advanced Data Structures Lecture 1
Chapter 16: Linked Lists.
Linked List ADT used to store information in a list
C++ Programming:. Program Design Including
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Chapter 4 Link Based Implementations
Programming II (CS300) Chapter 07: Linked Lists and Iterators
Dynamic Data Structures and Generics
Programming II (CS300) Chapter 07: Linked Lists
Linked Lists Chapter 5 (continued)
Lecture 2 – Abstract Data Type (ADT)
CMPT 225 Lecture 6 – Review of Complexity Analysis using the Big O notation + Comparing List ADT class implementations.
CMPT 225 Lecture 5 – linked list.
Lecture 3 – Data collection List ADT
Lecture 4 – Data collection List ADT
CMPT 225 Lecture 7 – Stack.
Presentation transcript:

Unit 1 - Introducing Abstract Data Type (ADT) Part 3 – Slides 24 to end

end CMPT Anne Lavergne24... delete( ) if (head != NULL) // Move to the end of the list Node* current = head; // Anchor while (current -> next != NULL) current = current -> next; // Then what???

Issue with Traverse Using “current -> next”? Using “current -> next -> next”? -> called “Look Ahead” CMPT Anne Lavergne25

Look Ahead Advantage: Disadvantage: CMPT Anne Lavergne26

Deletion – with previous end CMPT Anne Lavergne27

Insertion - end CMPT Anne Lavergne28

doubly headed singly linked list CMPT Anne Lavergne29 Advantages: Disadvantages:

Deletion - end CMPT Anne Lavergne30

CMPT Anne Lavergne31 singly headed doubly linked list Advantages: Disadvantages:

doubly headed doubly linked list CMPT Anne Lavergne32 Advantages: Disadvantages:

linked lists are very flexible CMPT Anne Lavergne33 singly headed singly linked circular list singly headed doubly linked circular list

Be Careful Do not confuse components of a linked list (attributes of List ADT class) ◦ Such as “head” and “tail” with local variables of various methods manipulating linked list ◦ Such as “current” and “previous” CMPT Anne Lavergne34

Activity - Problem Statement We are asked to develop a software application to manage customer accounts These accounts are to be ◦ listed in ascending alphabetical sort order of customer last name or in ascending numerical sort order of customer SIN a lot Let’s design our underlying data structure to our ADT class ◦ Let’s create a linked list that would allow us to perform these operations in O(n) CMPT Anne Lavergne35

Back to solving our Problem Well, in this course, We shall design an ADT Remember where we were when we took our Side Trip – Pointers and linked lists? 36

Back to solving our Problem We were in the process of solving our social network problem using a data collection List ADT but this time (in Part 3), we decided to implement this data collection List ADT class using a linked list as opposed to an array -> linked-based implementation of List ADT class CMPT Anne Lavergne37

Part of our List ADT design remain unchanged 1.Our list ADT remains a position-oriented 2.The operations our List ADT needs to perform remain unchanged  Determine the number of elements in a list  Insert an element at a given position in the list  Remove the element at a given position in the list  Remove all the elements from the list  Look at (get) the element at a given position in the list  Replace (set) an element at a given position on the list -> List ADT Public Interface remains unchanged CMPT Anne Lavergne38 Step 2 – Design of our List ADT

UML class diagram unchanged CMPT Anne Lavergne39 FriendsBook - numberOfMembers : integer - members : List + join( newProfile : Profile ) : void + leave( profile : Profile ) : void + modify( profile : Profile ) : void + search( target : Profile ) : void Profile - name : String - image : String - status : String - numberOfFriends : integer - friends : String[0..*] 0..* + getElementCount( ) : integer + insert( newPosition : integer, newElement: Profile) : boolean + remove( position : integer ) : boolean + clear( ) : void + getElement(position : integer) : Profile + setElement(position : integer, newElement : Profile) : void - elementCount : integer - elements : Profile[0..*] + addFriend( aFriend : String ) : void

CMPT Anne Lavergne40 Step 2 – Design of our List ADT So, the only thing that needs to be redesigned, i.e., changed is the underlying data structure of our List ADT and the algorithm of its methods -> Basically: what is behind the wall! FriendsBook (client code) Public interface ListADT Insert Etc... Program linked list of Profile objects Class attributes (private):

Step 3 - Solution # 3 – Code Posted on our course web site Week 5: ◦ Code demonstrating the use of an ADT (linked-based implementation of our List ADT):  FriendsBook Application - version 5: ListADT.h, and ListADT.cppListADT.hListADT.cpp ◦ Note that the FriendsBook and the class Profile have not changed CMPT Anne Lavergne41

Let’s compare Solution #2 with Solution #3 Let’s compare Solution #2 in which we implemented our data collection List ADT class using an array as an underlying data structure (CDT) with Solution #3 in which we implemented our data collection List ADT class using a linked list (singly headed singly linked – SHSL) as an underlying data structure (CDT) CMPT Anne Lavergne42

CMPT Anne Lavergne FriendsBook (client code) Public interface ListADT Program array of Profile objects Insert Etc... Class attributes (private): Solution # 2 Comparing them using Wall diagrams FriendsBook (client code) Public interface ListADT Insert Etc... Program linked list of Profile objects Class attributes (private): Solution # 3

Advantages of using ADT’s These 2 implementations (array-based and linked-based) of our data collection List ADT class demonstrate some of the advantages of using an ADT (as opposed to not using an ADT) in our solution: 1.Application easy to understand, design, implement, maintain, debug, test because each class is assigned only one responsibility 2.Ease s/w development team work 3.Ease modification (of private/hidden section of ADT) 4.Ease reusability CMPT Anne Lavergne44

Disadvantages of using ADT’s CMPT Anne Lavergne45 1. Must design the Public Interface of our ADT very well since, once it has been released, it cannot change 2. Need to write getters and setters