In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the example analysis of Java sequence table, which is very detailed and has certain reference value. Friends who are interested must finish it!
I. Preface
Sequence table is a commonly used one, learning and understanding is very important, and the sequence table lays a foundation for future learning.
II. Definition of order
A sequential representation of a linear table saved as an array in computer memory that occupies a continuous set of storage in memory
Unit, where each element is stored in turn.
Third, realize the API design of sequence table 3.1
3.2 Code implementation of sequence table
Define a generic class (the advantage of a generic class is that it can accept any type)
/ / define a generic class public class SequenceList {}
Define member variables in a generic class
/ / define an array of storage elements (first defined as generic) private T [] eles; / / define a variable to represent the number of elements in the sequence table private int N
Defines a constructor that is used to initialize member variables
/ / add a constructor to initialize the member variable public SequenceList (int capacity) {/ / accept a capacity length / / initialize the array this.eles = (T []) new Object [capacity]; / / create an Object type so it needs to be strongly converted to T [] / / the length of the initialization sequence table this.N = 0;}
The following functions are implemented:
Set a linear table to an empty table
/ / set a linear table to an empty table public void clear () {/ / just change the length of the sequential table to 0 to this.N=0;} / / the reason we use this is that it must refer to member variables to prevent local variables from having the same name as member variables. / / whenever member variables are involved, try to modify them with this.
Determine whether the linear table is empty or not
/ / to determine whether the current linear table is empty or not, public boolean isEmpty () {/ / is empty only by judging the number of elements in the linear table return this.N==0;}
Get the length of the linear table
/ / get the length of the linear table public int length () {/ / just return N to return this.N;}
Get the element of the I position
/ / get the element public T get (int I) at the specified I position {/ / because the sequence table is an array, you only need to find the element through the index to return eles [I];}
Add the element t to the linear table
/ / add the element t public void insert (T t) {/ / T to the linear table the type of the element represented by / / this representation is very ingenious, adding 1 to the element while assigning the position of index N to the element eles [nymph +] = t; / / this representation is equivalent to els [N] = t;}
Insert element t at index I
/ / insert the element t public void insert (int for T t) at the beginning of the I element {/ / first move the element at the I index and the following elements backward one by one (int index=N;index > I indexMe -) {/ / give the value of the previous bit to the latter bit eles [index] = Els [index-1] } / / then put the t element at the I index, and the array length plus 1 eles [I] = t; Numeric;} insert the diagram:
Delete the element at the specified location I and return it
/ / deletes the element at the specified position I and returns the element public T remove (int I) {/ / first defines an element in which a variable records the position of I, and then returns the value T current=eles [I]; / / the element after the index I moves forward one bit in turn (for (int index=0;index)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.