SlideShare uma empresa Scribd logo
1 de 28
Chapter 3
Data Abstraction:
The Walls
© 2005 Pearson Addison-Wesley. All rights reserved 3-2
Abstract Data Types
• Typical operations on data
– Add data to a data collection
– Remove data from a data collection
– Ask questions about the data in a data
collection
© 2005 Pearson Addison-Wesley. All rights reserved 3-3
Abstract Data Types
• Data abstraction
– Asks you to think what you can do to a
collection of data independently of how you do it
– Allows you to develop each data structure in
relative isolation from the rest of the solution
© 2005 Pearson Addison-Wesley. All rights reserved 3-4
Abstract Data Types
• Abstract data type (ADT)
– An ADT is composed of
• A collection of data
• A set of operations on that data
– Specifications of an ADT indicate
• What the ADT operations do, not how to implement
them
– Implementation of an ADT
• Includes choosing a particular data structure
© 2005 Pearson Addison-Wesley. All rights reserved 3-5
Abstract Data Types
Figure 3.4
A wall of ADT operations isolates a data structure from the program that uses it
© 2005 Pearson Addison-Wesley. All rights reserved 3-6
The ADT List
• Except for the first and last items, each item
has a unique predecessor and a unique
successor
• Head or front do not have a predecessor
• Tail or end do not have a successor
© 2005 Pearson Addison-Wesley. All rights reserved 3-7
The ADT List
• Items are referenced by their position within
the list
• Specifications of the ADT operations
– Define the contract for the ADT list
– Do not specify how to store the list or how to
perform the operations
• ADT operations can be used in an
application without the knowledge of how
the operations will be implemented
© 2005 Pearson Addison-Wesley. All rights reserved 3-8
The ADT List
• ADT List operations
– Create an empty list
– Determine whether a list is empty
– Determine the number of items in a list
– Add an item at a given position in the list
– Remove the item at a given position in the list
– Remove all the items from the list
– Retrieve (get) item at a given position in the list
© 2005 Pearson Addison-Wesley. All rights reserved 3-9
The ADT List
• The ADT sorted list
– Maintains items in sorted order
– Inserts and deletes items by their values, not
their positions
© 2005 Pearson Addison-Wesley. All rights reserved 3-10
Designing an ADT
• The design of an ADT should evolve
naturally during the problem-solving
process
• Questions to ask when designing an ADT
– What data does a problem require?
– What operations does a problem require?
© 2005 Pearson Addison-Wesley. All rights reserved 3-11
Implementing ADTs
• Choosing the data structure to represent the
ADT’s data is a part of implementation
– Choice of a data structure depends on
• Details of the ADT’s operations
• Context in which the operations will be used
• Implementation details should be hidden
behind a wall of ADT operations
– A program would only be able to access the
data structure using the ADT operations
© 2005 Pearson Addison-Wesley. All rights reserved 3-12
An Array-Based ADT List
• A list’s items are stored in an array items
• Both an array and a list identify their items
by number
© 2005 Pearson Addison-Wesley. All rights reserved 3-13
An Array-Based ADT List
• A list’s kth
item will be stored in items[k-
1]
Figure 3.11 An array-based implementation of the ADT list
© 2005 Pearson Addison-Wesley. All rights reserved 3-14
Array-Based ADT List Implementation
// *************************************
// Header file ListA.h for the ADT list
// Array-based implementation
// *************************************
const int MAX_LIST = maximum-size-of-list;
typedef desired-type-of-list-item ListItemType;
class List{
public:
List(); // default constructor
// destructor is supplied by
// compiler
© 2005 Pearson Addison-Wesley. All rights reserved 3-15
Array-Based ADT List Implementation
// list operations:
bool isEmpty() const;
// Determines whether a list is empty.
// Precondition: None.
// Postcondition: Returns true if the
// list is empty; otherwise returns
// false.
© 2005 Pearson Addison-Wesley. All rights reserved 3-16
Array-Based ADT List Implementation
int getLength() const;
// Determines the length of a list.
// Precondition: None.
// Postcondition: Returns the number of
// items that are currently in the list.
© 2005 Pearson Addison-Wesley. All rights reserved 3-17
Array-Based ADT List Implementation
void insert(int index,
ListItemType newItem,
bool& success);
// Inserts an item into the list at
// position index.
// Precondition: index indicates the
// position at which the item should be
// inserted in the list.
// Postcondition: If insertion is
// successful, newItem is at position
// index in the list, and other items are
// renumbered accordingly, and success is
// true; otherwise success is false.
// Note: Insertion will not be successful
// if index < 1 or index > getLength()+1.
© 2005 Pearson Addison-Wesley. All rights reserved 3-18
Array-Based ADT List Implementation
void remove(int index, bool& success);
// Deletes an item from the list at a
// given position.
// Precondition: index indicates where
// the deletion should occur.
// Postcondition: If 1 <= index <=
// getLength(), the item at position
// index in the list is deleted, other
// items are renumbered accordingly,
// and success is true; otherwise success
// is false.
© 2005 Pearson Addison-Wesley. All rights reserved 3-19
Array-Based ADT List Implementation
void retrieve(int index,
ListItemType& dataItem,
bool& success) const;
// Retrieves a list item by position.
// Precondition: index is the number of
// the item to be retrieved.
// Postcondition: If 1 <= index <=
// getLength(), dataItem is the value of
// the desired item and success is true;
// otherwise success is false.
© 2005 Pearson Addison-Wesley. All rights reserved 3-20
Array-Based ADT List Implementation
private:
ListItemType items[MAX_LIST];
// array of list items
int size;
// number of items in list
int translate(int index) const;
// Converts the position of an item in a
// list to the correct index within its
// array representation.
}; // end List class
© 2005 Pearson Addison-Wesley. All rights reserved 3-21
Array-Based ADT List Implementation
// **************************************
// Implementation file ListA.cpp for the ADT
// list
// Array-based implementation
// *****************************************
#include "ListA.h" //header file
List::List() : size(0){
} // end default constructor
© 2005 Pearson Addison-Wesley. All rights reserved 3-22
Array-Based ADT List Implementation
bool List::isEmpty() const{
return size == 0;
} // end isEmpty
© 2005 Pearson Addison-Wesley. All rights reserved 3-23
Array-Based ADT List Implementation
int List::getLength() const{
return size;
} // end getLength
© 2005 Pearson Addison-Wesley. All rights reserved 3-24
Array-Based ADT List Implementation
int List::translate(int index) const{
return index - 1;
} // end translate
© 2005 Pearson Addison-Wesley. All rights reserved 3-25
Array-Based ADT List Implementation
void List::insert(int index, ListItemType newItem,
bool& success){
success = (index >= 1) &&
(index <= size + 1) &&
(size < MAX_LIST);
if (success){
// make room for new item by shifting all
// items at positions >= index toward the end
// of the list (no shift if index == size+1)
for (int pos = size; pos >= index; --pos)
items[translate(pos+1)] = items[translate(pos)];
// insert new item
items[translate(index)] = newItem;
++size; // increase the size of the list by one
}
} // end insert
© 2005 Pearson Addison-Wesley. All rights reserved 3-26
Array-Based ADT List Implementation
void List::remove(int index, bool& success){
success = (index >= 1) && (index <= size) ;
if (success){
// delete item by shifting all items at
// positions > index toward the beginning
// of the list (no shift if index == size)
for (int fromPosition = index+1;
fromPosition <= size;
++fromPosition)
items[translate(fromPosition-1)] =
items[translate(fromPosition)];
--size; // decrease the size of the list by one
}
} // end remove
© 2005 Pearson Addison-Wesley. All rights reserved 3-27
Array-Based ADT List Implementation
void List::retrieve(int index, ListItemType& dataItem,
bool& success) const{
success = (index >= 1) && (index <= size);
if (success)
dataItem = items[translate(index)];
} // end retrieve
© 2005 Pearson Addison-Wesley. All rights reserved 3-28
Summary
• Data abstraction controls the interaction
between a program and its data structures
• Abstract data type (ADT): a set of data-
management operations together with the
data values upon which they operate
• An ADT should be fully defined before any
implementation decisions
• Hide an ADT’s implementation by defining
the ADT as a C++ class

Mais conteúdo relacionado

Mais procurados

Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2Self-Employed
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm03446940736
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptSeethaDinesh
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data StructureMeghaj Mallick
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSAjunnubabu
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
Queue data structure
Queue data structureQueue data structure
Queue data structureanooppjoseph
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked ListNinad Mankar
 

Mais procurados (20)

Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Linked list
Linked listLinked list
Linked list
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Hashing
HashingHashing
Hashing
 
Sorting
SortingSorting
Sorting
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Stack
StackStack
Stack
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 

Destaque

Abstract data types
Abstract data typesAbstract data types
Abstract data typesTony Nguyen
 
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Hassan Ahmed
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data typesjigeno
 
Data abstraction the walls
Data abstraction the wallsData abstraction the walls
Data abstraction the wallsHoang Nguyen
 
Preparation Data Structures 03 abstract data_types
Preparation Data Structures 03 abstract data_typesPreparation Data Structures 03 abstract data_types
Preparation Data Structures 03 abstract data_typesAndres Mendez-Vazquez
 
03 data abstraction
03 data abstraction03 data abstraction
03 data abstractionOpas Kaewtai
 
Slide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaSlide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaVisakh V
 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesHarry Potter
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsHarry Potter
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - AbstractionMichael Heron
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)eShikshak
 
บทที่ 2 สถาปัตยกรรม
บทที่ 2 สถาปัตยกรรมบทที่ 2 สถาปัตยกรรม
บทที่ 2 สถาปัตยกรรมPrinceStorm Nueng
 
Toward a Standardized XMAN Presentation Layer with Consideration of User Inte...
Toward a Standardized XMAN Presentation Layer with Consideration of User Inte...Toward a Standardized XMAN Presentation Layer with Consideration of User Inte...
Toward a Standardized XMAN Presentation Layer with Consideration of User Inte...Bassel Saab
 

Destaque (20)

Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Algo>Abstract data type
Algo>Abstract data typeAlgo>Abstract data type
Algo>Abstract data type
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
 
Data abstraction the walls
Data abstraction the wallsData abstraction the walls
Data abstraction the walls
 
Preparation Data Structures 03 abstract data_types
Preparation Data Structures 03 abstract data_typesPreparation Data Structures 03 abstract data_types
Preparation Data Structures 03 abstract data_types
 
03 data abstraction
03 data abstraction03 data abstraction
03 data abstraction
 
Slide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaSlide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schema
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Lec3
Lec3Lec3
Lec3
 
Chapter03
Chapter03Chapter03
Chapter03
 
2CPP14 - Abstraction
2CPP14 - Abstraction2CPP14 - Abstraction
2CPP14 - Abstraction
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
 
บทที่ 2 สถาปัตยกรรม
บทที่ 2 สถาปัตยกรรมบทที่ 2 สถาปัตยกรรม
บทที่ 2 สถาปัตยกรรม
 
Singly link list
Singly link listSingly link list
Singly link list
 
Toward a Standardized XMAN Presentation Layer with Consideration of User Inte...
Toward a Standardized XMAN Presentation Layer with Consideration of User Inte...Toward a Standardized XMAN Presentation Layer with Consideration of User Inte...
Toward a Standardized XMAN Presentation Layer with Consideration of User Inte...
 

Semelhante a Abstract data types

Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...davidwarner122
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using Ccpjcollege
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdfarshin9
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdffirstchoiceajmer
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 
unit 1_Linked list.pptx
unit 1_Linked list.pptxunit 1_Linked list.pptx
unit 1_Linked list.pptxssuser7922b8
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queueRajkiran Nadar
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfmayorothenguyenhob69
 
For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdfFor this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdffashiongallery1
 
please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdfankit11134
 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxalanfhall8953
 
Please do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfPlease do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfaioils
 
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfclearvisioneyecareno
 
please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfaggarwalopticalsco
 
Design your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdfDesign your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdfprajeetjain
 
lect- 3&4.ppt
lect- 3&4.pptlect- 3&4.ppt
lect- 3&4.pptmrizwan38
 

Semelhante a Abstract data types (20)

Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using C
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdf
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
unit 1_Linked list.pptx
unit 1_Linked list.pptxunit 1_Linked list.pptx
unit 1_Linked list.pptx
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
 
12888239 (2).ppt
12888239 (2).ppt12888239 (2).ppt
12888239 (2).ppt
 
For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdfFor this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdf
 
please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdf
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
 
List,Stacks and Queues.pptx
List,Stacks and Queues.pptxList,Stacks and Queues.pptx
List,Stacks and Queues.pptx
 
Please do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfPlease do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdf
 
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdf
 
please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdf
 
Design your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdfDesign your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdf
 
lect- 3&4.ppt
lect- 3&4.pptlect- 3&4.ppt
lect- 3&4.ppt
 

Mais de Poojith Chowdhary (20)

Voltage multiplier
Voltage multiplierVoltage multiplier
Voltage multiplier
 
Implementation of MIS and its methods
Implementation of MIS and its methodsImplementation of MIS and its methods
Implementation of MIS and its methods
 
THE LIGHT EMITTING DIODE
THE LIGHT EMITTING DIODETHE LIGHT EMITTING DIODE
THE LIGHT EMITTING DIODE
 
High k dielectric
High k dielectricHigh k dielectric
High k dielectric
 
The science of thought
The science of thoughtThe science of thought
The science of thought
 
Child prodigy,savant and late boomers
Child prodigy,savant and late boomersChild prodigy,savant and late boomers
Child prodigy,savant and late boomers
 
Us wireless cable television
Us wireless cable televisionUs wireless cable television
Us wireless cable television
 
1116297 634468886714442500
1116297 6344688867144425001116297 634468886714442500
1116297 634468886714442500
 
Photo transistors
Photo transistorsPhoto transistors
Photo transistors
 
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
 
8051 micro controller
8051 micro controller8051 micro controller
8051 micro controller
 
8085 micro processor
8085 micro processor8085 micro processor
8085 micro processor
 
Quantum mechanics
Quantum mechanicsQuantum mechanics
Quantum mechanics
 
Function generator
Function generatorFunction generator
Function generator
 
Resistors
ResistorsResistors
Resistors
 
The new seven wonders of the world
The new seven wonders of the worldThe new seven wonders of the world
The new seven wonders of the world
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
 
The new seven wonders of the world
The new seven wonders of the worldThe new seven wonders of the world
The new seven wonders of the world
 
Animal lifecycles
Animal lifecyclesAnimal lifecycles
Animal lifecycles
 
Resistors
ResistorsResistors
Resistors
 

Último

ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 

Último (20)

ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 

Abstract data types

  • 2. © 2005 Pearson Addison-Wesley. All rights reserved 3-2 Abstract Data Types • Typical operations on data – Add data to a data collection – Remove data from a data collection – Ask questions about the data in a data collection
  • 3. © 2005 Pearson Addison-Wesley. All rights reserved 3-3 Abstract Data Types • Data abstraction – Asks you to think what you can do to a collection of data independently of how you do it – Allows you to develop each data structure in relative isolation from the rest of the solution
  • 4. © 2005 Pearson Addison-Wesley. All rights reserved 3-4 Abstract Data Types • Abstract data type (ADT) – An ADT is composed of • A collection of data • A set of operations on that data – Specifications of an ADT indicate • What the ADT operations do, not how to implement them – Implementation of an ADT • Includes choosing a particular data structure
  • 5. © 2005 Pearson Addison-Wesley. All rights reserved 3-5 Abstract Data Types Figure 3.4 A wall of ADT operations isolates a data structure from the program that uses it
  • 6. © 2005 Pearson Addison-Wesley. All rights reserved 3-6 The ADT List • Except for the first and last items, each item has a unique predecessor and a unique successor • Head or front do not have a predecessor • Tail or end do not have a successor
  • 7. © 2005 Pearson Addison-Wesley. All rights reserved 3-7 The ADT List • Items are referenced by their position within the list • Specifications of the ADT operations – Define the contract for the ADT list – Do not specify how to store the list or how to perform the operations • ADT operations can be used in an application without the knowledge of how the operations will be implemented
  • 8. © 2005 Pearson Addison-Wesley. All rights reserved 3-8 The ADT List • ADT List operations – Create an empty list – Determine whether a list is empty – Determine the number of items in a list – Add an item at a given position in the list – Remove the item at a given position in the list – Remove all the items from the list – Retrieve (get) item at a given position in the list
  • 9. © 2005 Pearson Addison-Wesley. All rights reserved 3-9 The ADT List • The ADT sorted list – Maintains items in sorted order – Inserts and deletes items by their values, not their positions
  • 10. © 2005 Pearson Addison-Wesley. All rights reserved 3-10 Designing an ADT • The design of an ADT should evolve naturally during the problem-solving process • Questions to ask when designing an ADT – What data does a problem require? – What operations does a problem require?
  • 11. © 2005 Pearson Addison-Wesley. All rights reserved 3-11 Implementing ADTs • Choosing the data structure to represent the ADT’s data is a part of implementation – Choice of a data structure depends on • Details of the ADT’s operations • Context in which the operations will be used • Implementation details should be hidden behind a wall of ADT operations – A program would only be able to access the data structure using the ADT operations
  • 12. © 2005 Pearson Addison-Wesley. All rights reserved 3-12 An Array-Based ADT List • A list’s items are stored in an array items • Both an array and a list identify their items by number
  • 13. © 2005 Pearson Addison-Wesley. All rights reserved 3-13 An Array-Based ADT List • A list’s kth item will be stored in items[k- 1] Figure 3.11 An array-based implementation of the ADT list
  • 14. © 2005 Pearson Addison-Wesley. All rights reserved 3-14 Array-Based ADT List Implementation // ************************************* // Header file ListA.h for the ADT list // Array-based implementation // ************************************* const int MAX_LIST = maximum-size-of-list; typedef desired-type-of-list-item ListItemType; class List{ public: List(); // default constructor // destructor is supplied by // compiler
  • 15. © 2005 Pearson Addison-Wesley. All rights reserved 3-15 Array-Based ADT List Implementation // list operations: bool isEmpty() const; // Determines whether a list is empty. // Precondition: None. // Postcondition: Returns true if the // list is empty; otherwise returns // false.
  • 16. © 2005 Pearson Addison-Wesley. All rights reserved 3-16 Array-Based ADT List Implementation int getLength() const; // Determines the length of a list. // Precondition: None. // Postcondition: Returns the number of // items that are currently in the list.
  • 17. © 2005 Pearson Addison-Wesley. All rights reserved 3-17 Array-Based ADT List Implementation void insert(int index, ListItemType newItem, bool& success); // Inserts an item into the list at // position index. // Precondition: index indicates the // position at which the item should be // inserted in the list. // Postcondition: If insertion is // successful, newItem is at position // index in the list, and other items are // renumbered accordingly, and success is // true; otherwise success is false. // Note: Insertion will not be successful // if index < 1 or index > getLength()+1.
  • 18. © 2005 Pearson Addison-Wesley. All rights reserved 3-18 Array-Based ADT List Implementation void remove(int index, bool& success); // Deletes an item from the list at a // given position. // Precondition: index indicates where // the deletion should occur. // Postcondition: If 1 <= index <= // getLength(), the item at position // index in the list is deleted, other // items are renumbered accordingly, // and success is true; otherwise success // is false.
  • 19. © 2005 Pearson Addison-Wesley. All rights reserved 3-19 Array-Based ADT List Implementation void retrieve(int index, ListItemType& dataItem, bool& success) const; // Retrieves a list item by position. // Precondition: index is the number of // the item to be retrieved. // Postcondition: If 1 <= index <= // getLength(), dataItem is the value of // the desired item and success is true; // otherwise success is false.
  • 20. © 2005 Pearson Addison-Wesley. All rights reserved 3-20 Array-Based ADT List Implementation private: ListItemType items[MAX_LIST]; // array of list items int size; // number of items in list int translate(int index) const; // Converts the position of an item in a // list to the correct index within its // array representation. }; // end List class
  • 21. © 2005 Pearson Addison-Wesley. All rights reserved 3-21 Array-Based ADT List Implementation // ************************************** // Implementation file ListA.cpp for the ADT // list // Array-based implementation // ***************************************** #include "ListA.h" //header file List::List() : size(0){ } // end default constructor
  • 22. © 2005 Pearson Addison-Wesley. All rights reserved 3-22 Array-Based ADT List Implementation bool List::isEmpty() const{ return size == 0; } // end isEmpty
  • 23. © 2005 Pearson Addison-Wesley. All rights reserved 3-23 Array-Based ADT List Implementation int List::getLength() const{ return size; } // end getLength
  • 24. © 2005 Pearson Addison-Wesley. All rights reserved 3-24 Array-Based ADT List Implementation int List::translate(int index) const{ return index - 1; } // end translate
  • 25. © 2005 Pearson Addison-Wesley. All rights reserved 3-25 Array-Based ADT List Implementation void List::insert(int index, ListItemType newItem, bool& success){ success = (index >= 1) && (index <= size + 1) && (size < MAX_LIST); if (success){ // make room for new item by shifting all // items at positions >= index toward the end // of the list (no shift if index == size+1) for (int pos = size; pos >= index; --pos) items[translate(pos+1)] = items[translate(pos)]; // insert new item items[translate(index)] = newItem; ++size; // increase the size of the list by one } } // end insert
  • 26. © 2005 Pearson Addison-Wesley. All rights reserved 3-26 Array-Based ADT List Implementation void List::remove(int index, bool& success){ success = (index >= 1) && (index <= size) ; if (success){ // delete item by shifting all items at // positions > index toward the beginning // of the list (no shift if index == size) for (int fromPosition = index+1; fromPosition <= size; ++fromPosition) items[translate(fromPosition-1)] = items[translate(fromPosition)]; --size; // decrease the size of the list by one } } // end remove
  • 27. © 2005 Pearson Addison-Wesley. All rights reserved 3-27 Array-Based ADT List Implementation void List::retrieve(int index, ListItemType& dataItem, bool& success) const{ success = (index >= 1) && (index <= size); if (success) dataItem = items[translate(index)]; } // end retrieve
  • 28. © 2005 Pearson Addison-Wesley. All rights reserved 3-28 Summary • Data abstraction controls the interaction between a program and its data structures • Abstract data type (ADT): a set of data- management operations together with the data values upon which they operate • An ADT should be fully defined before any implementation decisions • Hide an ADT’s implementation by defining the ADT as a C++ class