Want to see the Java version of the data structure, to understand some of the tree operations, write a sequential table familiar with
1 Packagecom.sqlist;2 3 /**4 * @authorXiangfei5 * Define a sequential table6 *7 */8 Public classSqllist {9 Final intDeflen = 10;Ten intMaxLen; One intCurlen; A Object elements[]; - - /** the * Default constructor method - */ - Publicsqllist () { -MaxLen =Deflen; +Curlen = 0; -elements =NewObject[maxlen]; + } A /** at * Initialize a data table based on one data and maximum length - * @paramArray - * @paramMaxLen - */ - PublicSqllist (Object array[],intmaxlen) { - This. MaxLen = array.length > MaxLen?Array.length:maxlen; inCurlen =Array.Length; -elements =Newobject[ This. MaxLen]; to + //Copy - for(inti = 0; i < MaxLen; i++){ theElements[i] =Array[i]; * } $ }Panax Notoginseng /** - * @paramsqllist the * Copy Construction method + */ A Publicsqllist (sqllist sqllist) { the This. MaxLen =Sqllist.maxlen; + This. Curlen =Sqllist.curlen; - //with a deep copy here . $elements =Newobject[ This. MaxLen]; $ //Copy - for(inti = 0; I < This. MaxLen; i++){ -Elements[i] =Sqllist.elements[i]; the } - }Wuyi /** the * Insert element position to specified position - * @paramelement Wu * @paramposition - * @return About */ $ Public BooleanInsertelement (Object element,intposition) { - if(Position < 0 | | position >=maxlen) - return false; - Else{ A inti = curlen-1; + while(I >position) { theElements[i] = elements[i-1]; - } $Elements[position] =element; the return true; the } the } the /** - * Delete the element at the specified location in * @paramposition the * @return the */ About PublicObject Deleteelement (intposition) { the if(Position < 0 | | position >=Curlen) the return NULL; the Else{ +Object Elementdel =Elements[position]; - inti =position; the while(I <Curlen) {BayiElements[i] = elements[i + 1]; the } the returnElementdel; - } - } the /** the * Print all the elements the */ the Public voidshowsqllist () { - for(inti = 0; i < Curlen; i++) the { theSystem.out.print (elements[i].tostring () + ""); the }94 } the}
Test class (Only one construction method is measured here, other methods are also very coarse)
1 Packagecom.sqlist;2 3 /**4 * Test Order table5 * @authorXiangfei6 *7 */8 Public classSqllisttest {9 Public Static voidMain (String args[]) {TenInteger array_int[] =NewInteger[]{1, 2, 3}; OneSqllist sqllist =NewSqllist (Array_int, 3); A - sqllist.showsqllist (); - } the}
Java Sequential table