Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java data structures - the linear form of the single-chain applications     - NET Developers need to know some Linux commands (Linux)

- Python2 ---- function using dictionaries (Programming)

- To install and use Docker under linux (Server)

- xargs Detailed description (Linux)

- Oracle 12C with multi-column index (Database)

- Hadoop1.2.1 plug compilation (Server)

- How Linux system password security guarantee (Linux)

- JavaScript event handling Detailed (Programming)

- Ubuntu installation module Python rq (Linux)

- Tmux Getting Start (Linux)

- Docker Build a Java compiler environment (Linux)

- How to run in support UDp Docker container JBoss data virtualization GA (Server)

- Oracle 11g principle study Dataguard (Database)

- To configure Samba to share files with Windows under CentOS (Linux)

- Linux system Passwd file detailed analysis (Linux)

- Use netcat [nc] command on Linux and Unix port scan (Server)

- SQLite (Database)

- How to set IonCube Loaders in Ubuntu (Linux)

- Network traffic monitoring ntopng (Linux)

- Docker data container protection the pros and cons (Server)

 
         
  Java data structures - the linear form of the single-chain applications
     
  Add Date : 2017-01-08      
         
       
         
  Single list of the inverse position, is to order the list of existing single elements upside down.

Mentioned before the whole table to create a single list, once said there are two ways: head and tail interpolation interpolation;
In my version of Java LinkedList, add the method used is the end of interpolation.
The single list is just the inverse position to take advantage of the first interpolation.

Here is my Java code, before the establishment of the code on the basis of

/ **
 * @TODO Single list added elements, the first interpolation
 * @param E data elements
 * @return True
 * /
public boolean addFirst (E e) {
    FOLinkedNode < E> node = new FOLinkedNode < E> (e);
    if (header.getE () == null) {
        header.setE (e);
    } Else {
        node.addNext (header);
        header = node;
    }
    this.size ++;
    return true;
}
Recommended to copy this code to a previous version of the Java LinkedList (FOLinkedList) in.

Algorithm time complexity is O (n)

The whole idea of solving the problem is as follows:

Establish pointer p, used to traverse the list;
Establish pointer q, q p node traversal back and compared with the p value;
If q and p values are equal, then delete q. If there is a subsequent node q, q will be the predecessor and successor nodes linked q; or directly start the next iteration.
Java code below, it is recommended to copy the code to a previous version of the Java LinkedList (FOLinkedList) in.

/ **
 * Remove duplicate nodes @TODO
 * @param Foll need to remove duplicate node singly linked list
 * @return Foll single list after deleting duplicate nodes
 * /
public static FOLinkedList removeRepeatElement (FOLinkedList foll) {
    FOLinkedNode p = foll.header;
    if (foll.header == null) {
        return foll;
    }
    while (p.next! = null) {
        FOLinkedNode q = p.next;
        while (q.next! = null) {
            if (q.next.getE (). equals (p.getE ())) {
                q.addNext (q.next.next);
                foll.size--;
            } Else {
                q = q.next;
            }
        }
        p = p.next;
    }
    return foll;
}
Time performance of the algorithm is O (n-th power of 2)

Detailed description of the problem:

Incremented orderly A, B two merge into one list element value by non-increasing (allow the same value) ordered list C.

Problem-solving ideas:

The use of A, B two tables incremental and orderly features of the current node in turn taken by comparing the current value of the smaller off, C is inserted into the head of the table, thanks to the first interpolation method, first find the smallest the value of the node C will at the end of the table, and so on, so get C table was non-incremental and orderly. Decreasing increments here modify the implementation according to the nature of the need for specific code. Tips are given in the code.

/ **
     * @TODO Two data elements of type "integer" increasing (or decreasing) single-chain merger by a single call list
     * @param BFoll single list b
     * @return C singly linked list c
     * (Non-consolidated results of decreasing (or non-incremental), depending on the chosen method of inserting a, b of the list Ascending Descending nature and merge functions)
     * /
    public FOLinkedList < Integer> merge (FOLinkedList < Integer> bFoll) {
        FOLinkedList < Integer> c = new FOLinkedList < Integer> ();
        FOLinkedNode < Integer> a = (FOLinkedNode < Integer>) this.header;
        FOLinkedNode < Integer> b = bFoll.header;
        Integer eTemp = new Integer (0);
        while (a! = null && b! = null) {
            if (a.getE () < = b.getE ()) {
                eTemp = a.getE ();
                a = a.next;
            } Else {
                eTemp = b.getE ();
                b = b.next;
            }
            // Here you can use interpolation head or tail interpolation
            c.add (eTemp);
// C.addFirst (eTemp);
    }
    if (a == null) {
        a = b;
    }
    while (a! = null) {
        c.add (a.getE ());
        a = a.next;
    }
    return c;
}
Incremented orderly A, B chain merged into non-decreasing list C, tail-interpolation can be realized.
Specific operation need to modify the code, the code above can be modified to insert an element of the first interpolation method or tail interpolation.

Time performance of the algorithm consists of two linked lists to be combined to determine the number of elements, namely O (m + n)
     
         
       
         
  More:      
 
- Linux three ways to set environment variables (Linux)
- Ubuntu resolve sudo: source: command not found error (Linux)
- Linux supports serial output method (Linux)
- Some MySQL interview questions (Database)
- Multi-core CPU, multi-threading and parallel computation (Linux)
- Linux, Chrome browser font settings beautification (Linux)
- Linux startup and logon security settings (Linux)
- First start with Kali Linux 2.0 (Linux)
- The Java Properties class action (Programming)
- See how --nand flash timing diagram of a read operation Comments (Programming)
- Ubuntu 15.04 and CentOS 7 to deploy .NET, Mono and DNX (Server)
- Thinking in Java study notes - initialization and cleanup (Programming)
- Linux (CentOS) SSH login without password authentication (Linux)
- linux firewall configuration (Linux)
- Let Linux boot methods to enter characters interface and set FrameBuffer resolution methods (Linux)
- MySQL function: group_concat () function (Database)
- rpm package specify the installation path (Linux)
- Why JavaScript basic types can invoke methods (Programming)
- KVM QEMU virtual machine installation configuration under CentOS (Linux)
- Hadoop connection failed or stuck processing (Server)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.