Java Reference
In-Depth Information
i < =h . s i z e )
while (2
j=2
i;
if (j < h. size && h. label [j+1] > h. label [j])
j ++;
if (h. label [i] < h. label [j])
{ tmp=h . label [i];
h. label [i]=h. label [j];
h. label [j]=tmp;
i=j ; }
else break ;
}
return h. label [h. size 1];
}
8.4 Object-oriented data-structures: Methods
We have so far explained data-structures and their basic operations using the
basic concepts of arrays and linked lists . The functions manipulating these
elementary data-structures have been all static functions so far. That means
that we had to pass the data-structure as an argument of the function, or to
declare the arrays/linked list as static variables of the class to be reached by
functions. Although we attached these basic static functions to the class by
inserting their code into the body of the class, this was not necessary. For
example, we could have designed a class Toolbox that contains all functions
operating on data-structures. Let us reexamine the code dealing with the linked
list of the previous chapter:
Program 8.6 Linked list with static functions
class List
int container ;
List next ;
// Constructor List(head, tail)
List( int element , List tail )
{ this .container=element;
this .next=tail; }
// Static function is used here
static int head( List l i s t )
{ return list . container ; }
}
 
Search WWH ::




Custom Search