Thought for the Day “Without leaps of imagination, or dreaming, we lose the excitement of possibilities. Dreaming, after all, is a form of planning.”

Slides:



Advertisements
Similar presentations
Queues Printer queues Several jobs submitted to printer Jobs form a queue Jobs processed in same order as they were received.
Advertisements

Linked Lists Geletaw S..
Inserting a Node into a Specified Position of a Linked List To create a node for the new item newNode = new Node(item); To insert a node between two nodes.
Queues and Linked Lists
Queue & List Data Structures & Algorithm Abstract Data Types (ADTs) ADT is a mathematically specified entity that defines a set of its instances,
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
1 Queues (5.2) CSE 2011 Winter May Announcements York Programming Contest Link also available from.
CHAPTER 4 Queues. Queue  The queue, like the stack, is a widely used data structure  A queue differs from a stack in one important way  A stack is.
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Queue, Deque, and Priority Queue Implementations Chapter 11 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Chapter 7 Stacks II CS Data Structures I COSC 2006
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
“Planning is bringing the future into the present so that you can do something about it now.” – Alan Lakein Thought for the Day.
ليست هاي پيوندي Linked Lists ساختمان داده ها و الگوريتم ها.
Chapter Objectives  Learn how to represent a waiting line (queue)  Become proficient using the methods in the Queue  Understand how to implement the.
Chapter 8 Queue I CS Data Structures I COSC2006 April 24, 2017
1 Chapter 7 The Linked List as a Data Structure. 2 The List ADT A list is a list of elements. The list of elements consist of the data acted upon by list.
“When we quit thinking primarily about ourselves and our own self-preservation, we undergo a truly heroic transformation of consciousness.” – Joseph Campbell.
“The desire for safety stands against every great and noble enterprise.” – Tacitus Thought for the Day.
Linked List.  Is a series of connected nodes, where each node is a data structure with data and pointer(s) Advantages over array implementation  Can.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
Lecture No.05 Data Structures Dr. Sohail Aslam.  Josephus Problem #include "CList.cpp" void main(int argc, char *argv[]) { CList list; int i, N=10, M=3;
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
© 2004 Goodrich, Tamassia Queues. © 2004 Goodrich, Tamassia Stacks2 The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow.
Section 3.7 Linked-Based Implementations
Chapter 16: Linked Lists.
Elementary Data Structures
C++ Programming:. Program Design Including
Queues 5/11/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Linked List Introduction
Week 4 - Friday CS221.
Linked Lists Chapter 5 (continued)
Queues Rem Collier Room A1.02
Data Structures and Algorithms
Week 3 - Friday CS221.
Stacks.
Chapter 6: The Stack Abstract Data Type
Queues Queues Queues.
8-1.
Introduction to Data Structures
8-1.
Queue, Deque, and Priority Queue Implementations
Queue, Deque, and Priority Queue Implementations
THURSDAY, OCTOBER 17 IN LAB
Linked Lists.
Stacks, Queues, and Deques
A Data Structure Bestiary
Linked Lists: Implementation of Queue & Deque
A Data Structure Bestiary
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
Queue and Priority Queue Implementations
Chapter 14: Queue and Priority Queue Implementations
COMPUTER 2430 Object Oriented Programming and Data Structures I
Linked Lists.
Programming II (CS300) Chapter 07: Linked Lists and Iterators
A List Implementation That Links Data
Data Structures and Algorithms
Stacks: Implemented using Linked Lists
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Chapter 4 Queues.
Linked Lists Chapter 5 (continued)
Programming II (CS300) Chapter 07: Linked Lists
Queues: Implemented using Linked Lists
Stacks, Queues, and Deques
Doubly Linked List Implementation
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Linked Lists Chapter 5 (continued)
A List Implementation That Links Data
Presentation transcript:

Thought for the Day “Without leaps of imagination, or dreaming, we lose the excitement of possibilities. Dreaming, after all, is a form of planning.” – Gloria Steinem

Doubly-, Circularly-Linked List with Header Node

Doubly-, Circularly-Linked List with Header Node An empty list: head

Advantages No special cases The list is never empty! We can move freely through the list in either direction Still cannot access elements “at random”

A Java Class for Deques Use a doubly-, circularly-linked list with a header node Class diagram: Deque header addLeft, addRight, removeLeft, removeRight, rightHead, leftHead, isEmpty

The Deque Class public class Deque<T> { private class DequeNode { public T data; public DequeNode lt, // Ptr to left node rt; // Ptr to right node } // inner class DequeNode private DequeNode header; // Ptr to header . . . } // class Deque

The Deque Class: Constructor public Deque () // Constructor { // Create header node header = new DequeNode(); header.lt = header; header.rt = header; } // Constructor header

The addLeft Method public void addLeft (T item) // Add item to left end { DequeNode newNode = new DequeNode(); newNode.data = item; newNode.rt = header.rt; newNode.lt = header; header.rt.lt = newNode; header.rt = newNode; } // addLeft newNode a header

Redrawing this: header a

The addLeft Method (cont.) public void addLeft (T item) // Add item to left end { DequeNode newNode = new DequeNode(); newNode.data = item; newNode.rt = header.rt; newNode.lt = header; header.rt.lt = newNode; header.rt = newNode; } // addLeft newNode b header a

Redrawing this: header a b

Comments No special cases The list is never empty public void addLeft (T item) // Add item to left end { DequeNode newNode = new DequeNode(); newNode.data = item; newNode.rt = header.rt; newNode.lt = header; header.rt.lt = newNode; header.rt = newNode; } // addLeft

Removing an Element public T removeLeft () // Remove item from left end { if (header.rt == header) throw new EmptyException(…); DequeNode tmpPtr = header.rt; T tmpData = tmpPtr.data; header.rt = tmpPtr.rt; tmpPtr.rt.lt = header; return tmpData; } // removeLeft

Examining an Element and Checking for an Empty Deque public T rightHead () // Return item at right end { if (header.lt == header) throw new EmptyException(…); return header.lt.data; } // rightHead public boolean isEmpty () // TRUE if no items in deque { return header.lt == header; } // isEmpty

Doubly-, Circularly-Linked List with Header Node Can be used for any type of list ADT not just deques Removes the need for special cases Simplifies algorithms no “previous” pointers required

Applications of Deques Very general data structure Can be used to implement stacks or queues Problem solving partly prioritise some possible solutions Applications needing more flexible list handling card games, etc.

Summary of List ADTs in Chapters Four and Five List of int Generic Lists Stacks Queues Deques ADT IntegerVector ArrayStack ArrayQueue Array IntegerList ObjectList GenericList ListStack ListQueue Deque Linked List