Skip to content

Instantly share code, notes, and snippets.

@ayoolaao
Created March 9, 2018 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayoolaao/ee7c7eb0dfa733543eedf94c0989baa5 to your computer and use it in GitHub Desktop.
Save ayoolaao/ee7c7eb0dfa733543eedf94c0989baa5 to your computer and use it in GitHub Desktop.
static public MyLinkedSort[] split(MyLinkedSort l){ // TODO
// parameter is a List
// it returns an array of size 2
// the 0th element is the left list
// the first element is the right list
MyLinkedSort left = l;
MyLinkedSort right = l;
Node leftFirst = left.first;
Node rightFirst = right.first;
int size = l.N;
Node cycleLeft = new Node();
Node cycleRight = new Node();
cycleLeft = leftFirst;
cycleRight = rightFirst;
int i = 1;
while(i < size/2) {
cycleLeft = cycleLeft.next;
cycleRight = cycleRight.next;
i++;
}
rightFirst = cycleRight.next;
cycleLeft.next = null;
left.first = leftFirst;
left.N = size/2;
right.first = rightFirst;
right.N = size - left.N;
MyLinkedSort[] splited = {left, right};
return splited;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment