Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualswiftcoder

Posted 18 January 2013 - 10:46 AM

What's wrong with the naive solution, where you maintain 3 separate ranges, and linearly search for the pivot?

 

 

def find_split<T>(r : range<T>, pivot : T):
    left : range<T> = r
    centre : range<T> = r
    right : range<T> = r
   
    while centre.front() != pivot:
        right.popFront()
        centre.popFront()
   
    while len(centre) > 1:
        left.popBack()
        centre.popBack()

    return (left, centre, right)

#1swiftcoder

Posted 18 January 2013 - 09:14 AM

What's wrong with the naive solution, where you maintain 3 separate ranges, and linearly search for the pivot?

 

 

def find_split<T>(r : range<T>, pivot : T):
    left : range<T> = r
    centre : range<T> = r
    right : range<T> = r
   
    while centre.front() != pivot:
        right.popFront()
        centre.popFront()
   
    while len(centre) > 1:
        left.popFront()
        centre.popFront()

    return (left, centre, right)

 


PARTNERS