Suche senden
Hochladen
Abstract data types
•
Als PPT, PDF herunterladen
•
8 gefällt mir
•
19,807 views
Poojith Chowdhary
Folgen
basic of ADT in data structure
Weniger lesen
Mehr lesen
Bildung
Technologie
Melden
Teilen
Melden
Teilen
1 von 28
Jetzt herunterladen
Empfohlen
Abstract Data Types
Abstract Data Types
karthikeyanC40
Data structure ppt
Data structure ppt
Prof. Dr. K. Adisesha
Linked list
Linked list
akshat360
Tree - Data Structure
Tree - Data Structure
Ashim Lamichhane
Arrays
Arrays
SARITHA REDDY
Binary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
Integrity Constraints
Integrity Constraints
madhav bansal
stack & queue
stack & queue
manju rani
Empfohlen
Abstract Data Types
Abstract Data Types
karthikeyanC40
Data structure ppt
Data structure ppt
Prof. Dr. K. Adisesha
Linked list
Linked list
akshat360
Tree - Data Structure
Tree - Data Structure
Ashim Lamichhane
Arrays
Arrays
SARITHA REDDY
Binary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
Integrity Constraints
Integrity Constraints
madhav bansal
stack & queue
stack & queue
manju rani
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
Self-Employed
Complexity of Algorithm
Complexity of Algorithm
Muhammad Muzammal
queue & its applications
queue & its applications
somendra kumar
Array data structure
Array data structure
maamir farooq
Graph traversals in Data Structures
Graph traversals in Data Structures
Anandhasilambarasan D
linked list in data structure
linked list in data structure
shameen khan
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
Selection sorting
Selection sorting
Himanshu Kesharwani
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
Data structure & its types
Data structure & its types
Rameesha Sadaqat
Introduction to data structures and Algorithm
Introduction to data structures and Algorithm
Dhaval Kaneria
Data Structure (Queue)
Data Structure (Queue)
Adam Mukharil Bachtiar
Python list
Python list
Mohammed Sikander
Priority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
Queue ppt
Queue ppt
SouravKumar328
Data Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
Tree in data structure
Tree in data structure
Daffodil International University
Doubly Linked List
Doubly Linked List
Ninad Mankar
Array ppt
Array ppt
Kaushal Mehta
Binary Search Tree
Binary Search Tree
sagar yadav
Abstract Data Types
Abstract Data Types
Reggie Niccolo Santos
Abstract data types
Abstract data types
Luis Goldster
Weitere ähnliche Inhalte
Was ist angesagt?
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
Self-Employed
Complexity of Algorithm
Complexity of Algorithm
Muhammad Muzammal
queue & its applications
queue & its applications
somendra kumar
Array data structure
Array data structure
maamir farooq
Graph traversals in Data Structures
Graph traversals in Data Structures
Anandhasilambarasan D
linked list in data structure
linked list in data structure
shameen khan
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
Selection sorting
Selection sorting
Himanshu Kesharwani
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
Data structure & its types
Data structure & its types
Rameesha Sadaqat
Introduction to data structures and Algorithm
Introduction to data structures and Algorithm
Dhaval Kaneria
Data Structure (Queue)
Data Structure (Queue)
Adam Mukharil Bachtiar
Python list
Python list
Mohammed Sikander
Priority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
Queue ppt
Queue ppt
SouravKumar328
Data Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
Tree in data structure
Tree in data structure
Daffodil International University
Doubly Linked List
Doubly Linked List
Ninad Mankar
Array ppt
Array ppt
Kaushal Mehta
Binary Search Tree
Binary Search Tree
sagar yadav
Was ist angesagt?
(20)
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
Complexity of Algorithm
Complexity of Algorithm
queue & its applications
queue & its applications
Array data structure
Array data structure
Graph traversals in Data Structures
Graph traversals in Data Structures
linked list in data structure
linked list in data structure
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
Selection sorting
Selection sorting
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Data structure & its types
Data structure & its types
Introduction to data structures and Algorithm
Introduction to data structures and Algorithm
Data Structure (Queue)
Data Structure (Queue)
Python list
Python list
Priority Queue in Data Structure
Priority Queue in Data Structure
Queue ppt
Queue ppt
Data Structures- Part5 recursion
Data Structures- Part5 recursion
Tree in data structure
Tree in data structure
Doubly Linked List
Doubly Linked List
Array ppt
Array ppt
Binary Search Tree
Binary Search Tree
Andere mochten auch
Abstract Data Types
Abstract Data Types
Reggie Niccolo Santos
Abstract data types
Abstract data types
Luis Goldster
Algo>Abstract data type
Algo>Abstract data type
Ain-ul-Moiz Khawaja
Abstract data types
Abstract data types
Tony 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...
Hassan Ahmed
11 abstract data types
11 abstract data types
jigeno
Data abstraction the walls
Data abstraction the walls
Hoang Nguyen
Preparation Data Structures 03 abstract data_types
Preparation Data Structures 03 abstract data_types
Andres Mendez-Vazquez
03 data abstraction
03 data abstraction
Opas Kaewtai
Slide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schema
Visakh V
Abstract data types
Abstract data types
Harry Potter
Algo>ADT list & linked list
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
Data structures and algorithms
Data structures and algorithms
Harry Potter
Lec3
Lec3
Saad Gabr
Chapter03
Chapter03
春男 洪
2CPP14 - Abstraction
2CPP14 - Abstraction
Michael Heron
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
eShikshak
บทที่ 2 สถาปัตยกรรม
บทที่ 2 สถาปัตยกรรม
PrinceStorm Nueng
Singly link list
Singly link list
Rojin Khadka
Toward a Standardized XMAN Presentation Layer with Consideration of User Inte...
Toward a Standardized XMAN Presentation Layer with Consideration of User Inte...
Bassel Saab
Andere mochten auch
(20)
Abstract Data Types
Abstract Data Types
Abstract data types
Abstract data types
Algo>Abstract data type
Algo>Abstract data type
Abstract 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...
11 abstract data types
11 abstract data types
Data abstraction the walls
Data abstraction the walls
Preparation Data Structures 03 abstract data_types
Preparation Data Structures 03 abstract data_types
03 data abstraction
03 data abstraction
Slide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schema
Abstract data types
Abstract data types
Algo>ADT list & linked list
Algo>ADT list & linked list
Data structures and algorithms
Data structures and algorithms
Lec3
Lec3
Chapter03
Chapter03
2CPP14 - Abstraction
2CPP14 - Abstraction
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
บทที่ 2 สถาปัตยกรรม
บทที่ 2 สถาปัตยกรรม
Singly 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...
Ähnlich wie 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...
davidwarner122
Data Structure Using C
Data Structure Using C
cpjcollege
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
arshin9
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdf
firstchoiceajmer
TSAT Presentation1.pptx
TSAT Presentation1.pptx
Rajitha Reddy Alugati
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
ajoy21
unit 1_Linked list.pptx
unit 1_Linked list.pptx
ssuser7922b8
Data structure , stack , queue
Data structure , stack , queue
Rajkiran Nadar
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
mayorothenguyenhob69
12888239 (2).ppt
12888239 (2).ppt
SrinivasanCSE
For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdf
fashiongallery1
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.pdf
ankit11134
Data structures in c#
Data structures in c#
SivaSankar Gorantla
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
alanfhall8953
List,Stacks and Queues.pptx
List,Stacks and Queues.pptx
UmatulSaboohSaleem1
Please do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdf
aioils
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdf
clearvisioneyecareno
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.pdf
aggarwalopticalsco
Design your own List ADT named StringList to provide the following .pdf
Design your own List ADT named StringList to provide the following .pdf
prajeetjain
lect- 3&4.ppt
lect- 3&4.ppt
mrizwan38
Ähnlich wie 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...
Data 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 .pdf
Everything 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.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
unit 1_Linked list.pptx
unit 1_Linked list.pptx
Data 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.pdf
12888239 (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.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.pdf
Data structures in c#
Data structures in c#
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
List,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.pdf
you 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.pdf
Design 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.ppt
Mehr von Poojith Chowdhary
Voltage multiplier
Voltage multiplier
Poojith Chowdhary
Implementation of MIS and its methods
Implementation of MIS and its methods
Poojith Chowdhary
THE LIGHT EMITTING DIODE
THE LIGHT EMITTING DIODE
Poojith Chowdhary
High k dielectric
High k dielectric
Poojith Chowdhary
The science of thought
The science of thought
Poojith Chowdhary
Child prodigy,savant and late boomers
Child prodigy,savant and late boomers
Poojith Chowdhary
Us wireless cable television
Us wireless cable television
Poojith Chowdhary
1116297 634468886714442500
1116297 634468886714442500
Poojith Chowdhary
Photo transistors
Photo transistors
Poojith Chowdhary
8086 micro processor
8086 micro processor
Poojith Chowdhary
8051 micro controller
8051 micro controller
Poojith Chowdhary
8085 micro processor
8085 micro processor
Poojith Chowdhary
Quantum mechanics
Quantum mechanics
Poojith Chowdhary
Function generator
Function generator
Poojith Chowdhary
Resistors
Resistors
Poojith Chowdhary
The new seven wonders of the world
The new seven wonders of the world
Poojith Chowdhary
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
Poojith Chowdhary
The new seven wonders of the world
The new seven wonders of the world
Poojith Chowdhary
Animal lifecycles
Animal lifecycles
Poojith Chowdhary
Resistors
Resistors
Poojith Chowdhary
Mehr von Poojith Chowdhary
(20)
Voltage multiplier
Voltage multiplier
Implementation of MIS and its methods
Implementation of MIS and its methods
THE LIGHT EMITTING DIODE
THE LIGHT EMITTING DIODE
High k dielectric
High k dielectric
The science of thought
The science of thought
Child prodigy,savant and late boomers
Child prodigy,savant and late boomers
Us wireless cable television
Us wireless cable television
1116297 634468886714442500
1116297 634468886714442500
Photo transistors
Photo transistors
8086 micro processor
8086 micro processor
8051 micro controller
8051 micro controller
8085 micro processor
8085 micro processor
Quantum mechanics
Quantum mechanics
Function generator
Function generator
Resistors
Resistors
The new seven wonders of the world
The new seven wonders of the world
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
The new seven wonders of the world
The new seven wonders of the world
Animal lifecycles
Animal lifecycles
Resistors
Resistors
Kürzlich hochgeladen
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
Sayali Powar
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
GeoBlogs
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
EduSkills OECD
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
Thiyagu K
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
Thiyagu K
microwave assisted reaction. General introduction
microwave assisted reaction. General introduction
Maksud Ahmed
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
VS Mahajan Coaching Centre
mini mental status format.docx
mini mental status format.docx
PoojaSen20
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
nomboosow
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
TechSoup
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
iammrhaywood
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
SafetyChain Software
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
National Information Standards Organization (NISO)
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Pooja Nehwal
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
RaunakKeshri1
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
Kürzlich hochgeladen
(20)
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
microwave assisted reaction. General introduction
microwave assisted reaction. General introduction
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
mini mental status format.docx
mini mental status format.docx
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Abstract data types
1.
Chapter 3 Data Abstraction: The
Walls
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
Jetzt herunterladen