Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java data structures - the linear form of the single-chain applications     - Node.js v4.0.0 installation configuration on Ubuntu 14.04 / 15.04 (Linux)

- Mac OS X command line to submit the local project to Git (Server)

- SLF4J Tutorial (Programming)

- Spring REST Exception Handling (Programming)

- Memcached and Redis (Linux)

- Storm basic framework for analysis (Programming)

- AWK principles and commands and file input (Linux)

- AWR Report (Database)

- Linux top command to get started (Linux)

- After Ubuntu Password Forgot your way back (Linux)

- C ++ virtual functions Classic Insights (Programming)

- Android 5.1 OTA package compilation error (Programming)

- Ora-00020: maximum number of processes (500) exceeded (Database)

- Java garbage collection (Programming)

- Hadoop2.4.0 Eclipse plug-in making (Server)

- CentOS 6.5 installation and simple configuration Nginx (Server)

- Java, extends and implements Usage (Programming)

- Linux-du and df command (Linux)

- hadoop 2.7.1 High Availability Setup Deployment (Server)

- Git commands (Linux)

 
         
  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:      
 
- Hadoop 1 and 2.x installation notes (Server)
- Java data structures - the linear form of the single-chain applications (Programming)
- Oracle archive log full cause abnormal slow database performance (Database)
- Installation Yarock 1.1.4 Music Player in Ubuntu (Linux)
- CentOS7 minimized installation can not find the 'ifconfig' command - Repair Tips (Linux)
- Oracle 12c R2 new feature dbca command to create a standby database (Database)
- Linux System Getting Started Learning: Join cron job in Linux (Linux)
- VMware virtual machine to install CentOS 7 (Linux)
- Android Qemu GPS module (Programming)
- MySQL view (Database)
- VPS xen openvz kvm (Server)
- a virtual machine created migrated to host RHEL6.4 on Ubuntu 14.04 (Linux)
- Swift acquaintance of values and references, the circular reference, Agent Precautions (Programming)
- Close common port to protect server security (Linux)
- How to use the Linux terminal Git commands (Linux)
- To create a secure network firewall with iptables Under Linux (Linux)
- Hunk / Hadoop: Performance Best Practices (Server)
- Zabbix configuration of SNMP (Server)
- Use mysqldump MySQL database backup - Linux Shell Scripting (Database)
- Getting Started with Linux: Learn how to install and access CentOS 7 Remote Desktop on a VPS (Server)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.