Details about the operation of the linear table (Java, c two languages)

Source: Internet
Author: User

In the previous chapter of the study of linear table, some of the places are more ambiguous to take, but some difficult to understand the place spent a long time to understand .... Then write the code that exists on the blog. From today onwards, will re-data structure of this book go again, in C and Java two languages, as far as possible each part can be implemented in code, so that the impression is more profound, also is a re-learning C language ~ ~. And now the new semester began to learn Oracle, will also be some of the learning process code and key difficulties recorded, I hope you will pay attention to OH ~ ~

The concept of linear tables is mentioned in the previous article, and today, for the specific operation of the linear table (array implementation), is divided into the following parts

1.ListMakeEmpty () Create empty table

2.ElementTypeFindK (int *k, List L) returns the corresponding element according to the order K. Find (ElementType x,list L) linear table finding where X first appears

4.void Insert (ElementType x,int i,list L) Inserts an element X before order I

5.void Delete (ElementType x,int i, List L) remove

Java article:

/** * for linear table operation * * @author dy1201zhangshuyou * * 1. Find the first occurrence of x in the position * 2. Return the corresponding element according to the order * 3.Insert * 4.Delete */public class ListTestDemo01 {private int a[];p rivate int nelem;public ListTestDemo01 (int maxSize) {A = new Int[maxsize];nelem = A.leng th;} /** * Find the first occurrence of X position */public int find (int X, int[] A) {int i = 0;for (; i <= a.length; i++) {if (I <= a.length && Amp A[i] = = X) {return i;}} return-1;} /** * Returns the corresponding element according to the order */public int Findelem (int elem, int[] A) {for (int i = 0; I <= a.length; i++) {while (i = = Elem) {return A[I-1];}} return 0;} /** * Insert: Insert X into position I, you should move the elements behind the i-1 all backwards, and the length of the array to add 1 * @param i * @param A */public void Insert (int X, int i, int[] a) {I   NT J;if (i = = a.length) {//Table space is full, cannot insert System.out.println ("array is full"); Return means to abort the operation of the current function and return the operation to the caller. }if (I < 1 && i > a.length + 1) {//Check the insertion position for reasonableness System.out.println ("position not valid"); return; for (j = a.length-1;j > i-1; j--) a[j] = a[j-1]; A[i] = X;return;} /** * Delete: Deletes the element of the specified position I * @param i * @param A */public void Delete (int i, int[] A) {int j;if (i > A.length | | i < 1) {System.out.println ("exceeds the length of the array");}  Else{for (j = I;j < A.length-1; J + +) {A[j] = a[j + 1]; }}}public void Display () {for (int i = 0; i < Nelem; i++) {System.out.println (a[i]);}} public static void Main (String args[]) {ListTestDemo01 test = new ListTestDemo01 (7); int[] A = new int[] {10, 12, 21, 3, 4 , 5, 6};test. Insert (7, 2, A); SYSTEM.ERR.PRINTLN (test. Findelem (1, A)); SYSTEM.ERR.PRINTLN (test. Findelem (4, A)); SYSTEM.OUT.PRINTLN (test. Find (+, A)); System.out.println (); test. Delete (2, A); for (int i = 0;i < a.length-1;i++) {System.out.print (A[i] + "");}}}
C language article:
Put the C language code later: Don't be impatient.

Details about the operation of the linear table (Java, c two languages)

Related Article

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: 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.