List class.head NULL _class Cell { void *object; Cell *next; public:... } _class List { Cell *head; public:... }

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

CSCE 3110 Data Structures & Algorithm Analysis
Queues and Linked Lists
CS 367 – Introduction to Data Structures
Linear Lists – Linked List Representation
Data Structure HKOI training /4/2010 So Pak Yeung.
418115: II. Linked List A linked list can be thought of a chain of linked list elements. A linked list element contains a single data item, and contains.
1 Array-based Implementation An array Q of maximum size N Need to keep track the front and rear of the queue: f: index of the front object r: index immediately.
Data Structure Lecture-5
Ics202 Data Structures. hh tail head (b) LinkedList head tail Element datum next 3 Integer Element datum next 1 Integer Element datum next 4 Integer.
Queue Definition Ordered list with property: –All insertions take place at one end (tail) –All deletions take place at other end (head) Queue: Q = (a 0,
Queues. Queue Definition Ordered list with property: All insertions take place at one end (tail) All insertions take place at one end (tail) All deletions.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Doubly Linked Lists. One powerful variation of a linked list is the doubly linked list. The doubly linked list structure is one in which each node has.
1 Queues and Lists. QUEUES Very similar to stacks The only difference between them is in the order in which elements are processed. A stack uses a last-in/first-out.
Queue RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Doubly Linked List. COMP104 Doubly Linked Lists / Slide 2 Doubly Linked Lists * In a Doubly Linked List each item points to both its predecessor and successor.
Doubly Linked Lists Doubly Linked Lists: Introduction. Doubly Linked Lists: Implementation Doubly Linked Lists: Analysis Doubly Linked Lists: Creation.
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.
List class.head NULL _class Cell { void *item; Cell *next; public:... } _class List { Cell *head; public:... }
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Queue using an array. .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they.
Linked Lists1 Part-B3 Linked Lists. Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data structure consisting of a sequence.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Queues.
Circular List Next field in the last node contains a pointer back to the first node rather than null pointer From any point in such a list it is possible.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
IntNode Class class IntNode { public: int info; class IntNode *next; IntNode(int el, IntNode *ptr = 0) { info = el; next = ptr; } }; diagrammatic representation:
Josephus Problem: Build the Circular Linked List
Last meeting..Doubly Linked List  InsertToFront  InsertToEnd  Search  DeleteNode.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
Linked Lists Objects->Connected->by->Pointers. What is a Linked List? List: a collection Linked: any individual item points to another item to connect.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 11 – Data Structures.
Subject Name : Data Structure Using C Title : Linked Lists
UNIT II Queue. Syllabus Contents Concept of queue as ADT Implementation using linked and sequential organization. – linear – circular queue Concept –
1. Last Lecture Stacks and Queues implemented with a Linked List Doubly Linked Lists 2 Today.
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.
Lists (2). Circular Doubly-Linked Lists with Sentry Node Head.
CSC 205 Programming II Lecture 15 Linked List – Other Variations.
CSCI 62 Data Structures Dr. Joshua Stough September 25, 2008.
1 Queues and Lists. QUEUES Very similar to stacks The only difference between them is in the order in which elements are processed. A stack uses a last-in/first-out.
LINEAR LINKED LISTS The disadvantages of arrays: 1.The size of the array is fixed. 2.Large size of array??? 3. Inserting and deleting elements. If the.
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
CSCE 3110 Data Structures & Algorithm Analysis More on lists. Circular lists. Doubly linked lists.
JavaScript: The First Parts Part Eleven Douglas Crockford Yahoo! Inc.
CS162 - Topic #9 Lecture: Dynamic Data Structures –Deallocating all nodes in a LLL –Inserting nodes into sorted order Programming Assignment Questions.
Queue ADT for lining up politely. COSC 2006 queue2 Queue – simple collection class  first-in first-out (FIFO) structure insert new elements at one end.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Queues Dale Roberts, Lecturer
Unit 3 Linked Lists King Fahd University of Petroleum & Minerals
Linked List Stacks, Linked List Queues, Dequeues
Doubly Linked List Review - We are writing this code
Sequences 8/2/ :13 AM Linked Lists Linked Lists.
Algorithm for deleting a node from a singly linked list
Java collections library
Priority Queue.
Linked list insertion Head. Linked list insertion Head.
Doubly linked lists.
Queues.
Queues 12/3/2018 Queues © 2014 Goodrich, Tamassia, Goldwasser Queues.
18.5 Linked Queues Like a stack, a queue can be implemented using pointers and nodes Allows dynamic sizing, avoids issue of wrapping indices NULL front.
Sequences 12/8/2018 3:02 AM Linked Lists Linked Lists.
ADT list.
Queues A first-in, first-out or FIFO data structure.
Queues FIFO Enqueue Dequeue Peek.
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
BY PROF. IRSHAD AHMAD LONE.
Presentation transcript:

List class.head NULL _class Cell { void *object; Cell *next; public:... } _class List { Cell *head; public:... }

Insert objects into a List

List class.object NULL head

List class.object.cell = new Cell(); NULL head

List class NULL.object.cell cell->next = NULL; cell->object = object; NULL head

List class.object.cell head = cell; NULL head

List class head NULL

List class NULL cell = new Cell(); object head

List class NULL cell head cell->next = NULL; cell->object = object; object NULL

List class head->next = cell; NULL cell object head

List class head->next = cell; NULL head

Find and remove an object

List class - find an object and remove it head NULL

List class - find an object and remove it NULL if (find(head->object, object)) {... head

List class - find an object and remove it NULL if (find(ptr->next->object, object)) {.ptr head

List class - find an object and remove it NULL ptr = ptr->next;.ptr head

List class - find an object and remove it NULL if (find(ptr->next->object, object)) {.ptr head

List class - find an object and remove it NULL void *object = ptr->next->object _object head.ptr

List class - find an object and remove it NULL Cell *tmp = ptr->next;.ptr _object tmp head

List class - find an object and remove it NULL ptr->next = ptr->next->next; _object tmp head.ptr

List class - find an object and remove it NULL delete tmp; _object tmp head.ptr

List class - find an object and remove it NULL return object; _object head

Doubly Linked Lists

head NULL.tail

Doubly Linked Lists head NULL.tail

Doubly Linked Lists head NULL.tail NULL

Doubly Linked Lists head NULL tail NULL

A Queue

.tail Circularly linked list

.tail Queue: insert item at rear, remove at front

.tail Queue: remove from front void *object = tail->next->object; _object

.tail Queue: remove from front tmp = tail->next; _object TempTemp tmp

.tail Queue: remove from front _tail->next = tail->next->next; _object TempTemp tmp

.tail Queue: remove from front delete tmp; _object TempTemp tmp

.tail Queue: remove from front _return object; _object TempTemp

.tail Queue: remove from front _ TempTemp

.tail Queue: insert at rear _ TempTemp

.tail Queue: insert at rear _cell = new Cell(object); TempTemp _cell NULL

.tail Queue: insert at rear _cell->next = tail->next; TempTemp _cell

.tail Queue: insert at rear _tail->next = cell; TempTemp _cell

.tail Queue: insert at rear _tail = tail->next; TempTemp _cell