I have never read the data structures of other language versions, but I think java implementation methods are clever-using classes and objects for implementation. an array-based table defines a class to store a group of data. I define the ArrayListClass class and the method to operate arrays in the class. this is actually so simple, but the specific operation will encounter a lot of trouble!
In our ArrayListClass class, we should first include an array-type domain list to store data. In this way, data in the same array produces a positional relationship, data operations are easy. however, what data type is this array? We expect this table to be used for all data types. We cannot fix it simply into a certain type. therefore, we must make this data Common. The solution is to define a class as a superclass for all data types. check this DataElement:
Public abstract class DataElement {
Public abstract boolean equals (DataElement otherElement );
Public abstract int compareTo (DataElement otherElement );
Public abstract void makeCopy (DataElement otherElement );
Public abstract DataElement getCopy ();
}
It is defined as abstract and inherited and implemented when other data types are defined. I have defined two data types: IntElement and StringElement:
IntElement:
Public class IntElement extends DataElement {
Protected int num;
// Constructors
Public IntElement (){
Num = 0;
}
Public IntElement (int number ){
Num = number;
}
Public IntElement (IntElement otherElement ){
Num = otherElement. num;
}
/// Get-set Methods
Public void setNum (int number ){
Num = number;
}
Public int getNum (){
Return num;
}
/* (Non-Javadoc)
* @ See DataElement # equals (DataElement)
*/
Public boolean equals (DataElement otherElement ){
// TODO Auto-generated method stub
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.