Java Reference
In-Depth Information
u.add(array [ i ]) ;
return u;
}
A simple code demonstrating various calls of object methods is given below.
Observe that the data-structure is not passed as an argument since it is
encapsulated into the object as a field.
Program 8.14 Demonstrating various calls of object methods
public static void main( String [ ]
args )
int []
array = { 2,3,5,7,11,13,17,19,23 } ;
List u=FromArray(array) ;
u.add(1) ;
u. display() ;
u. delete (5) ;
u. display() ;
System . out . println (u . belongsTo (17) ) ;
System . out . println (u . belongsTo (24) ) ;
}
The result displayed in the console output is:
1->2->3->5->7->11->13->17->19->23->null
1->2->3->7->11->13->17->19->23->null
true
false
8.6 Stacks: Last in first out (LIFO) abstract
data-structures
Stacks are generic data-structures for storing incoming elements. However,
stacks depart from queues in the sense that the last arrived element is the
first pulled out. This is why stacks are also called LIFO data-structures: Last
in first out structures. The basic interface 5
of a stack is described by the two
following methods:
- Push : Add an element into the stack,
5 Java
also
provides
in
its
API
a
generic
stack
implementation.
See
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Stack.html
 
 
Search WWH ::




Custom Search