Today’s sharing started, please give us more advice ~

Today we are going to start learning to implement a Java based order table.

Outline of this content introduction:

1. A simple understanding of the sequence table

  • concept
  • know

3. Concrete implementation of the interface

  • Creating an initial variable
  • Print order table
  • Add elements
  • Determine whether it contains
  • Find the element subscript
  • Access to elements
  • Update the element
  • Remove elements
  • Gets the length of the order table
  • Clear order table

3. Complete the code presentation

1. A simple understanding of the sequence table

A sequential list is a linear structure in which data elements are stored in sequence by a sequence of storage cells with contiguous physical addresses. Generally, array storage is used. Add or delete data from the array.

The order table can be divided into:

Static order tables: Use arrays of fixed length for storage.

Dynamic order table: use dynamically mined array storage.

Static sequential tables are suitable for scenarios where you know how much data you need to store.

Static order table of the fixed length array led to N fixed large, more open space waste, less open insufficient. Dynamic order tables are more flexible, allocating space dynamically as needed.

2. Interface implementation

Today we are going to implement a dynamic order table. Here are the interfaces that need to be supported.

Next, we will need to implement a specific method to achieve.

(1) Create initial variables

First we create a myArraylist class. Initially we create an integer array int [] elem, a valid length variable int usedSize, and write a constructor that defines the size of the array inside the method to make space for the array.

(2) Print the sequence table

A for loop iterates through the elements of the array, printing each element.

(3) Add elements

The implementation steps of this method:

1. Consider whether the value of the array subscript pos is valid

2. If pos is valid, add elements.

3. Consider that the array capacity is full and copy the array capacity.

(4) Determine whether elements are included

Returns true if the toFind we are looking for was found in the array, false if not.

(5) Find the subscript of the element

We iterate through the array and return the index of the array if we find the toFind we are looking for. If none is found, -1 is returned.

(6) Get the element of pos position

Return the value of the element in the array with subscript pos if pos is valid.

(7) Update the element value of pos position

If pos is valid, pass the value of value to the element subscript pos to change the value of the element.

(8) Delete elements

Delete method implementation steps:

1. Use the search method to find the index of the passed keyword. If the index cannot be found in the array, return.

2. Using the relation between I and useSize, assign the element with subscript I +1 to I, I ++, starting with I = index.

3. Delete one element, valid array usedSize – -.

(9) Obtain the length of the order table

Returns the value usedSize representing the effective length.

(10) Clear the order table

To clear the order table, we empty the array by setting the effective length to 0.

3. The realization of the complete sequence table

summary

The basic syntax of Java has been introduced a lot before, in the later Java learning, it is very important to understand the knowledge of basic data structure, the idea of data structure, can help us more clearly understand the idea of Solving problems in Java and so on.

Today’s share has ended, please forgive and give advice!