You are on page 1of 2

ABSTRACT DATA TYPES (ADT)

-An abstract data type is a data type defined by its operations only.
-Example:Automobile as an ADT operation:
Steer
Accelerate
Brake
Play radio
-Other example: Star Wars death star trash compaction operation (The walls
opening and closing to compact the trash and crush main characters)
Open
Close
-A list as an ADT: you can put it in an array, in a linked list, a fancier data
structure. As long as what is defined as a list has operations.
- Operation can be is empty
- Insert an element (at beginning, end, or somewhere in middle)
- Delete/remove
- Searching for value
- Sort list
- Clear the list
- Getting a value
- Getting length of the list
-in Java ADT is represented by interfaces implemented by classes, and then
methods correspond to operations.
-One implementation of lists ADT:
Linked Lists
o Idea: store 3, 52, -8 in a linked list
o Node contains two different types- stores an integer and
something that tells us where an integer is (two different classes)
o We need class I-node which will be an inner class in I-list where I
stands for Integer.
o PublicclassIlist{
//bunchofstuff
privateclassInode
{
//morestuff
}
}
We make the inner class private
o So the I-node class for storing 3, 52, -8:
PrivateclassInode
{
intdata;

Inodenext;//reference,declaringreference
//nextoftypeInode,youdontget
//anobjectuntilyouusekeywordnew//
(reference=pointer)
publicInode(intvalue)//constructor
{
data=value;
}
}
o Data field
Private I-node head;
o Some methods for I-list class:
publicbooleanisEmpty(){
returnhead==null;
}
//putvalueatbeginningoflist
publicbooleaninsertFirst(intvalue){
Inodep=newINode(value);
p.next=head;
head=p;
}
want:
publicbooleansearch(intvalue){
//requirestraversingthelist
//firstwritefindPlacemethod
}
publicInodefindPlace(intvalue)
^mustbeprivatesinceitisreferencingouterclass

You might also like