Abstract Data Types ADT: A set of objects and a set of operations on those objects. examples: integers: +, - , *, … Collection, insert, remove, … set:

Slides:



Advertisements
Similar presentations
COMP171 Fall 2005 Lists.
Advertisements

DATA STRUCTURES AND ALGORITHMS Prepared by İnanç TAHRALI
Linear Lists – Array Representation
1111 Abstract Data Types Cpt S 223. School of EECS, WSU.
Lists: An internal look
Linked Lists CENG 213 Data Structures.
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
The Template Class Chain Chain Linear list. Each element is stored in a node. Nodes are linked together using pointers.
Stacks.
Chapter 7 Stacks II CS Data Structures I COSC 2006
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 8 Stacks and Queues Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
1 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
C++ Classes and Data Structures Jeffrey S. Childs
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Chapter 5 – Dynamic Data Structure Par1: Abstract Data Type DATA STRUCTURES & ALGORITHMS Teacher: Nguyen Do Thai Nguyen
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,
Intro. to Data Structures Chapter 3: Lists, Stacks, Queues 1 Chapter 3 Lists, Stacks, and Queues Abstract Data Types (ADTs) Lists Stacks Queues.
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.
The List ADT A sequence of zero or more elements A 1, A 2, A 3, … A N-1 N: length of the list A 1 : first element A N-1 : last element A i : position i.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
M180: Data Structures & Algorithms in Java Linked Lists – Part 2 Arab Open University 1.
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.
1 Chapter 3 Lists, Stacks, and Queues Reading: Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
1 Linked Lists Chapter 3. 2 Objectives You will be able to: Describe an abstract data type for lists. Understand and use an implementation of a List ADT.
114 3/30/98 CSE 143 Collection ADTs [Chapter 4] /30/98 Collection ADTs  Many standard ADTs are for collections  Data structures that manage groups.
UNIT-V ABSTRACT DATA TYPE 1.LIST 2.STACK 3.QUEUE EC6301-II-ECE-C.
1 Data Structures and Algorithms Queue. 2 The Queue ADT Introduction to the Queue data structure Designing a Queue class using dynamic arrays Linked Queues.
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.
Unit – I Lists.
Cpt S 122 – Data Structures Abstract Data Types
CS505 Data Structures and Algorithms
CE 221 Data Structures and Algorithms
Lists CS 3358.
Data Abstraction: The Walls
CC 215 Data Structures Stack ADT
CSE 143 Linked Lists [Chapter , 8.8] 3/30/98.
Stacks.
Lists The List ADT.
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
Chapter 16-2 Linked Structures
Linked Lists.
Chapter 4 Linked Lists.
Linked List (Part I) Data structure.
Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors
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.
CMSC 341.
Doubly Linked List Implementation
The List, Stack, and Queue ADTs
Chapter 4 Linked Lists.
Data Abstraction: The Walls
Array-Based Implementations
CMSC 341.
Lists - I The List ADT.
Lists - I The List ADT.
CMSC 341.
Lists - I The List ADT.
CMSC 341 List 2.
General List.
Lists - I The List ADT.
Lists CMSC 202, Version 4/02.
Data Abstraction: The Walls
Lists CMSC 202, Version 4/02.
Doubly Linked List Implementation
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
Chapter 3 Lists, Stacks, and Queues
Lab 03 – Linked List.
Abstract Data Types Stacks CSCI 240
Data Structures & Programming
Presentation transcript:

Abstract Data Types ADT: A set of objects and a set of operations on those objects. examples: integers: +, - , *, … Collection, insert, remove, … set: union, intersection, complement, size, … In C++, the set of operations roughly corresponds to the public member functions of a class. Oct 12, 2001 CSE 373, Autumn 2001

ADTs continued Implementation details can be hidden: member functions access private data members and member functions. Functions outside the ADT can only access the public data members and functions. difference between software engineering and hacking: finding the balance between functionality, simplicity, flexibility, and performance. ADT Oct 12, 2001 CSE 373, Autumn 2001

List ADT list of size N: A1, A2, A3, …, AN The position of Ai is i. A list of size 0 is the empty list. operations : printList ( ) makeEmpty ( ) insert (x, pos) remove (x) findkth (k) … Oct 12, 2001 CSE 373, Autumn 2001

Array Implementation printList makeEmpty insert remove findkth Problems? A1 A2 A3 … AN Oct 12, 2001 CSE 373, Autumn 2001

Linked List Impl. insert delete A1 A2 A3 A4 x A1 A2 A3 A4 Oct 12, 2001 CSE 373, Autumn 2001

Sentinels Use a header or dummy node to simplify the code. header empty list A1 A2 A3 Oct 12, 2001 CSE 373, Autumn 2001

Linked Lists in C++ Weiss uses three classes to implement linked lists. IntListItr IntList A1 A2 A3 IntListNode Oct 12, 2001 CSE 373, Autumn 2001

IntListNode IntListNode represents one node of a list. class IntListNode { private: IntListNode (const int theData = 0, IntListNode * n = NULL) : data(theData), next(n) } int data; IntListNode * next; friend class IntList; friend class IntListItr; }; IntListNode represents one node of a list. Oct 12, 2001 CSE 373, Autumn 2001

IntListItr class IntListItr { public: IntListItr() : current(NULL) { } bool isPastEnd() const return (current == NULL); } void advance() if (!isPastEnd()) current = current->next; const int retrieve() const if (isPastEnd()) throw BadIterator(); return current->data; Oct 12, 2001 CSE 373, Autumn 2001

IntListNode * current; IntListItr(IntListNode * theNode) private: IntListNode * current; IntListItr(IntListNode * theNode) : current(theNode) { } friend class IntList; } // class IntListItr class IntList { public: // constructors ... bool isEmpty() const; void makeEmpty(); IntListItr zeroth() const; ... void insert (const int x, const IntListItr & p); IntListNode *header; } Oct 12, 2001 CSE 373, Autumn 2001

IntList functions IntList::IntList() { header = new IntListNode; } bool IntList::isEmpty() const return (header->next == NULL); IntListItr IntList::first() const return IntListItr(header->next); IntListItr IntList::find(const int x) const IntListNode *itr = header->next; while ((itr != NULL) && (itr->data != x)) itr = itr->next; return IntListItr(itr); Oct 12, 2001 CSE 373, Autumn 2001