Linear table merge

Source: Internet
Author: User

Category 1

Array merging, but the array cannot cross-border. To save memory, create an array to merge the array, and then assign a value to the array to be merged.

Package org. se;
// Merge linear tables
Public class arithMetic11 {
Public static int [] la = {, 4}; // use an array instead of a linear table
Public static int [] lb = {, 9 };
Public static int la_len; // get the array Length
Public static int lb_len;
 


Public arithMetic11 (){
Init ();
// TODO Auto-generated constructor stub
}

Public void Init () // initialize data
{
La_len = la. length; // obtain the array length
Lb_len = lb. length;
}
Public void ListInsert () // insert data
{
Int a; // used to store elements in lb


For (int I = 0; I <lb. length; I ++)
{
A = lb [I];

If (! (LocateElem (a) // determines whether la has an element equal to.
{
Int [] text = new int [++ la_len]; // defines a new array
// System. out. println (la_len); // text = la; if so, the text length is the same as the la length.
For (int j = 0; j <la_len-1; j ++)
{
// System. out. println (la_len );
Text [j] = la [j]; // copy la to text
}

Text [la_len-1] = a; // place a at the end of the new array
For (int x = 0; x <la_len; x ++)
{
GetElem (text );
// System. out. println (la_len );
System. out. println ("la [" + x + "]..." + la [x]);
}
}
}
}
Static boolean LocateElem (int e) // determines whether la has an element equal to.
{
Boolean B = true; // determines whether la has an element equal to.
For (int j = 0; j <la. length; j ++)
{
If (e! = La [j])
{
B = false;
}
Else
{
B = true;
}
}
Return B;
}

Public void GetElem (int [] p) // assign the new array to la
{
La = null;
La = p;
}
}

Category 2

Package org. se;


Public class test {


Static arithMetic11 am;

Public static void main (String [] args ){
Am = new arithMetic11 ();
Am. ListInsert ();
// TODO Auto-generated method stu
}
}

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.