Sequential storage of linear tables in Java implementation data structure

Source: Internet
Author: User
Tags int size
/** * @author Neosong * @date Sep, 2017 * 7:30:43 PM * Program of information: Define some linear structure operations * 1, define interfaces and define methods in them, interface is 100% Abstract class, there are only method headers, no method body */public interface Sqllist {int count ();//Seek length void clear ();//Empty Operation Boolean isempty ();  Null Boolean isfull ()//To determine if full void attend (t item);//attach operation void Insert (T item,int l);/insert operation void Delete (int i);//delete operation T  getelement (int i);//Fetch matrix int Locate (T item)//position}/* @date Sep, 2017 * 7:44:53 PM * Program of Information: Data Structure---Linear table--Realization of sequential table * 2. Implement the method defined in the interface/public class Sequencelist implements sqllist{//define the constructor to initialize the variable public Sequen Celist () {} public sequencelist (int size) {if (size>=0) {list= (t[]) New object[size];//initialize T type array list, cannot point to parent class object with subclass reference,
			Therefore, it is necessary to forcibly convert this.maxsize=size;
		Last=-1;
	else throw new RuntimeException ("initialization size cannot be less than 0" +size);
	
	
	
	
	private int last;//defines the position in which last element is saved the private int maxsize;//is used to define the maximum storage capacity of the order table, last<=maxsize private t[] list; Public T getlist (int index) {RetuRN List[index];
	public void setlist (int index,t value) {list[index]=value;
	public int GetLast () {return last;
	public void Setlast (int last) {this.last = last;
	public int getmaxsize () {return maxSize;
	The public void setmaxsize (int maxSize) {this.maxsize = maxSize;
	
	
	}//sequencelist[] List=new sequencelist[maxsize];
	Find length public int count () {return last+1;
		//Empty public void clear () {//setlast (-1);
	Setlast (-1);
	}//Determine if NULL public boolean IsEmpty () {return last==-1;  //Judge if full public boolean isfull () {return last==maxsize-1;//This place is wrong at the time you write it, no-1}//Additional---loops traverse to the last number, then add in public
	    	void attend (T item) {//To determine whether the linear table is full to enhance the robustness of the program if (Isfull ()) {System.out.println ("array is full");
	return;//End Method} List[++last]=item; //Insert List---Array, item---value l---position public void Insert (T item,int L) {//To determine if the array is full if (Isfull ()) {SYSTEM.OUT.P
			Rintln ("The array is full");
		Return //Determine if the value of L is correct if (l<1| | L>last+2) {System.out.println ("Incorrect location, please check");
		Return
		}//for (int i=last+1;i>l-1;i--) {//list[i]=list[i-1];//} List[l-1]=item; last++;//array last element position change}//delete list----array L----position public void Delete (int l) {///To determine whether the linear table is an empty if (IsEmpty ()) {Syst
			EM.OUT.PRINTLN ("Array is empty");
		Return } if (l<1| | L>count ()) {//This place calls the count () method, so when you return the last value in the Count method,//cannot use last++.
	        This will virtually increase the last value, so that when traversing the output array, the final number will be null System.out.println ("input data is incorrect");
		Return //formally delete code for (int i=l-1;i

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.