Created
June 25, 2014 05:39
-
-
Save hilda8519/ddec0a1e20ac8074e79c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
public class ListPartition { | |
public static void ListPartition(ListNode node, int x){ | |
ListNode beforeStart=null; | |
ListNode afterStart=null; | |
while (node!=null){ | |
ListNode next=node.next; | |
if(node.val<x){ | |
node.next=beforeStart; | |
beforeStart=node; | |
} | |
else{ | |
node.next=afterStart; | |
afterStart=node; | |
} | |
node=next; | |
} | |
if(beforeStart==null){ | |
return; | |
} | |
ListNode head=beforeStart; | |
while(beforeStart.next!=null){ | |
beforeStart=beforeStart.next; | |
} | |
beforeStart.next=afterStart; | |
return; | |
} | |
class ListNode { | |
int val; | |
ListNode next; | |
ListNode(int x, int i, int j, int k, int l, int m, int n, int o, int p, int q) { | |
val = x; | |
next = null; | |
} | |
} | |
public static void main(String[] args){ | |
ListNode ListNode = new ListNode(1,2,3,4,5,7,8,9,10,11 ); | |
System.out.print(ListPartition(ListNode, 10)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment