0% found this document useful (0 votes)
36 views2 pages

Public Class I List (//bunch of Stuff Private Class I Node (//more Stuff) )

An abstract data type (ADT) defines a data type by its operations rather than its structure. Examples of ADTs include automobiles with operations like steer, accelerate, and brake, and lists with operations like insert, delete, search, and sort. In Java, ADTs are represented by interfaces that define methods corresponding to the operations, and classes implement these interfaces. One implementation of a list ADT is a linked list, which stores elements in nodes that reference the next node. The nodes are implemented as a private inner class of the linked list class, with fields for the data and a next node reference.

Uploaded by

M. Alarcon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

Public Class I List (//bunch of Stuff Private Class I Node (//more Stuff) )

An abstract data type (ADT) defines a data type by its operations rather than its structure. Examples of ADTs include automobiles with operations like steer, accelerate, and brake, and lists with operations like insert, delete, search, and sort. In Java, ADTs are represented by interfaces that define methods corresponding to the operations, and classes implement these interfaces. One implementation of a list ADT is a linked list, which stores elements in nodes that reference the next node. The nodes are implemented as a private inner class of the linked list class, with fields for the data and a next node reference.

Uploaded by

M. Alarcon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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