CS 302 Data Structures Linked Lists.

Slides:



Advertisements
Similar presentations
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Advertisements

DATA STRUCTURES AND ALGORITHMS Prepared by İnanç TAHRALI
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
Lab 8 Ordered list. OVERVIEW In an ordered list the elements are maintained in ascending (or descending) order based on the data contained in the list.
Linked Lists CENG 213 Data Structures.
Introduction to Programming Lecture 39. Copy Constructor.
Lists + CS3240, L. Grewe 1. 2 Goals Use the C++ template mechanism fr defining generic data types Implement a circular linked list Implement a linked.
The Template Class Chain Chain Linear list. Each element is stored in a node. Nodes are linked together using pointers.
Implementing a Stack as a Linked Structure CS 308 – Data Structures.
1 Chapter 6 Lists Plus. ADT Sorted List Operations Transformers n MakeEmpty n InsertItem n DeleteItem Observers n IsFull n LengthIs n RetrieveItem Iterators.
Stacks  Standard operations: IsEmpty … return true iff stack is empty Top … return top element of stack Push … add an element to the top of the stack.
Helpful C++ Transitions
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
1 Nell Dale Chapter 6 Lists Plus Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Lists Lecture 16 Fri, Mar 3, Topics Lists List ADT Attributes Constructors Destructor Inspectors Mutators Facilitators Operators Other List Functions.
C++ Classes and Data Structures Jeffrey S. Childs
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Lecture 6 : Template Acknowledgement : courtesy of Prof. Dekai Wu lecture slides.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 8: Class Relationships Data Abstraction & Problem Solving.
1 Inside the Vector Class: with additional needed methods CPS212CPS212 Gordon College.
The Big Three Based on Weiss “Data Structures and algorithm Analysis CS240 Computer Science II.
1 Recall Definition of Stack l Logical (or ADT) level: A stack is an ordered group of homogeneous items (elements), in which the removal and addition of.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
Lab05. // // // Laboratory 5 ListLinked.h // // Class declaration for the linked implementation.
“When we quit thinking primarily about ourselves and our own self-preservation, we undergo a truly heroic transformation of consciousness.” – Joseph Campbell.
Lab 2 Point List. OVERVIEW In this laboratory, you explore lists in which each element is a two-dimensional point or (x,y) pair. We refer to this type.
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
Lab 6 Stack ADT. OVERVIEW The stack is one example of a constrained linear data structure. In a stack, the elements are ordered from most recently added.
What happens... l When a function is called that uses pass by value for a class object like our dynamically linked stack? StackType MakeEmpty Pop Push.
Chapter 6 Lists Plus. What is a Class Template? A class template allows the compiler to generate multiple versions of a class type by using type parameters.
Linked lists. Data structures to store a collection of items Data structures to store a collection of items are commonly used Typical operations on such.
The List ADT Reading: Sections 3.2, 3.3, 3.5.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
CSI 1340 Introduction to Computer Science II Chapter 6 Lists Plus.
Link-Based Implementations
Learning Objectives Pointers as dada members
CS505 Data Structures and Algorithms
Lecture 6 : Template Acknowledgement : courtesy of Prof. Dekai Wu lecture slides.
CSE 143 Linked Lists [Chapter , 8.8] 3/30/98.
C++ Plus Data Structures
Stack and Queue APURBO DATTA.
Linked lists Motivation: we can make arrays, but their functionality is slightly limited and can be difficult to work with Biggest issue: size management.
A Doubly Linked List There’s the need to access a list in reverse order prev next data dnode header 1.
Chapter 4 Linked Lists
LinkedList Class.
Doubly linked lists.
Pointers and Linked Lists
Chapter 16-2 Linked Structures
Trees 3: The Binary Search Tree
Linked Lists.
Chapter 4 Link Based Implementations
Chapter 4 Linked Lists.
Chapter 18: Linked Lists.
CMSC 341.
Doubly Linked List Implementation
Chapter 4 Linked Lists.
CMSC 341.
Lecture 15 Section 6.1 Mon, Feb 26, 2007
CMSC 341.
The Big 5 and Lists.
Containers: Queue and List
Chapter 8: Class Relationships
CMSC 341 List 2.
Lists CMSC 202, Version 4/02.
Lists CMSC 202, Version 4/02.
Doubly Linked List Implementation
Data Structures & Programming
Presentation transcript:

CS 302 Data Structures Linked Lists

Preliminaries A Node: Several nodes linked together

Preliminaries A head pointer to the first node

Time for some code: // Programming exercise 2 template <typename DataType> class List { public: List(int ignored = 0); List(const List& other); List& operator=(const List& other); ~List(); void insert(const DataType& newDataItem) throw (logic_error); void remove() throw (logic_error); void replace(const DataType& newDataItem) void clear(); bool isEmpty() const; bool isFull() const; void gotoBeginning() throw (logic_error); void gotoEnd() throw (logic_error); bool gotoNext() throw (logic_error); bool gotoPrior() throw (logic_error); DataType getCursor() const throw (logic_error); // Programming exercise 2 void moveToBeginning () throw (logic_error); // Programming exercise 3 void insertBefore(const DataType& newDataItem) void showStructure() const; private: class ListNode { public: ListNode(const DataType& nodeData, ListNode* nextPtr); DataType dataItem; ListNode* next; }; ListNode* head; ListNode* cursor;

Now to write some …. Constructor Destructor operator= … Shallow Copy vs Deep Copy …

End of Chapter 4