Sequencelist.java file
Package List;public class Sequencelist {private int list_init_size = 5;//The original size of the linked list private int INCREMENT =1;//list increment size private Object []sqlist = null;//list private int curindex=0;//current position/** * Initialize linked list * */public void Initlist () {sqlist = new object[list_i Nit_size];} /** * insert element into linked list * */public void insertlist (Object o) {if (curindex>list_init_size-1)//Determine if the current list is full {// Allocate space System.out.println ("Newly Allocated Space") from the new list; List_init_size+=increment;object []temp = new object[list_init_size];for (int i=0;i<curindex;i++) {temp[i]=SqList[ I];} Sqlist=null; Sqlist=temp;} If you do not let it contain duplicate elements in the list, add this code/*if (Iscontain (o)) {System.out.println ("This element is already included in the list" +o); Else{}*/sqlist[curindex++]= o;} /** * Determine if the list contains an element * */boolean Iscontain (Object o) {for (int i=0;i<curindex;i++) {if (Sqlist[i].equals (o)) {return true;}} return false;} /** * Delete an element in the list * * If the containing duplicate element is deleted * */public void Delete (Object o) {for (int i=0;i<curindex;i++) {if (Sqlist[i].equals (O)) {f or (int j=i;j<curindex-1;j++) {sqlist[j]=sqlist[j+1];} Curindex--;continue;} if (i==curindex-1) {SysteM.OUT.PRINTLN ("This element does not exist" +o);}}} /** * Gets an element in the list * */public Object getelement (int i) {if (i <= 0 | | i > Curindex) {System.out.println ("Get position exceeds number of elements in the list "+curindex);} return sqlist[i-1];} /** * Print List * */public void print () {for (int i=0;i<curindex;i++) {System.out.print (sqlist[i]+ "\ t");} System.out.println ();}}
Main function test
Package List;public class Sequencelistmain {public static void main (string[] args) {sequencelist sqlist = new Sequencelist (); Sqlist.initlist (); sqlist.insertlist (1); sqlist.insertlist (2); sqlist.insertlist (3); sqlist.insertlist (4); Sqlist.insertlist (5); sqlist.insertlist (6); Sqlist.delete (5); Sqlist.delete (9); sqlist.insertlist (1); SqList.print ( ); Sqlist.delete (1); Sqlist.print (); System.out.println ("The 2nd element is:" +sqlist.getelement (1)); System.out.println ("The 4th element is:" +sqlist.getelement (4));}}
Java Implementation order Chain list