1 PackageiYou.neugle.list;2 3 Public classMyseqlist<t> {4 Private intInitmaxsize = 10;5 Privatet[] list;6 Private intListlen = 0;7 8 Publicmyseqlist () {9 This. Init ();Ten } One A PublicMyseqlist (intsize) { - This. initmaxsize =size; - This. Init (); the } - - Public voidInit () { - This. List = (t[])Newobject[ This. Initmaxsize]; + } - + //Sequential table Add operations A Public BooleanAdd (T data) { at if( This. Listlen < This. Initmaxsize) { - This. List[listlen] =data; - This. listlen++; -System.out.println ("Insert succeeded"); - return true; - } inSYSTEM.OUT.PRINTLN ("Sequential table data is full"); - return false; to } + - //Sequential Table insert Operation the Public BooleanInsert (intp, T data) { * if(P < 0 | | p > This. initMaxSize-1) { $SYSTEM.OUT.PRINTLN ("Invalid Insert data location");Panax Notoginseng return false; - } the if( This. Listlen = = This. Initmaxsize) { +SYSTEM.OUT.PRINTLN ("Sequential table data is full"); A return false; the } + //fault-tolerant processing - if(P > This. Listlen) { $p = This. Listlen; $ This. list[p] =data; -}Else { - for(inti = This. listLen-1; I >= p; i--) { the This. list[i + 1] = This. List[i]; - }Wuyi This. list[p] =data; the } - This. listlen++; WuSystem.out.println ("Insert succeeded"); - return true; About } $ - //Sequential Table Delete operations - Public BooleanDelete (intp) { - if(P < 0 | | p > This. initMaxSize-1) { ASystem.out.println ("Delete data location illegal"); + return false; the } - for(inti = P; I <= This. listLen-1; i++) { $ This. list[i] = This. list[i + 1]; the } the This. listlen--; theSystem.out.println ("Delete succeeded"); the return true; - } in the //Order table by subscript lookup the PublicT Get (intp) { About if(P < 0 | | p > This. initMaxSize-1) { theSYSTEM.OUT.PRINTLN ("Lookup data does not exist"); the return NULL; the } + -System.out.println ("Find successful, data is:" + This. list[p]); the return This. list[p];Bayi } the the //Sequential Table Size - Public intSizeOf () { - return This. Listlen; the } the the Public voidPrint () { theSystem.out.print ("["); - for(inti = 0; I < This. list.length; i++) { theSystem.out.print ( This. List[i]); the if(I < This. list.length-1) { theSystem.out.print (",");94 } the } theSystem.out.println ("]"); the }98}
Java data structures and algorithms------linear tables (sequential table structure)