AndreiL
Welcome to AndreiL.
Enjoy your time.
Please log in.

# Binary search in a list of even than odd numbers - Python ## Binary search in a list of even than odd numbers - Python

 ` 1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334` `'''Created on Feb 15, 2012@author: sin'''n = int(raw_input("Insert range list number: "))x = int(raw_input("Insert searched number: "))a = range(0, n)print "The raw list: \n", adef prs(a): s = [] c = [] for i in range(0, len(a)): if a[i] % 2 == 0: s.append(a[i]) else: c.append(a[i]) s.extend(c) return sdef bs(s, x): p = 0; q = len(s) - 1 while 1: if q < p: return -1 m = (p + q) / 2 if s[m] < x: p = m + 1 elif s[m] > x: q = m - 1 else: return mprint "The list divided into even and odd numbers: \n", prs(a)print "Number", x, "is on position", bs(prs(a), x), "in the list."`

If you want this code:
Code:
`'''Created on Feb 15, 2012@author: sin'''n = int(raw_input("Insert range list number: "))x = int(raw_input("Insert searched number: "))a = range(0, n)print "The raw list: \n", adef prs(a):    s = []    c = []    for i in range(0, len(a)):        if a[i] % 2 == 0:            s.append(a[i])        else:            c.append(a[i])    s.extend(c)    return sdef bs(s, x):    p = 0; q = len(s) - 1    while 1:        if q < p:            return -1        m = (p + q) / 2        if s[m] < x:            p = m + 1        elif s[m] > x:            q = m - 1        else:            return mprint "The list divided into even and odd numbers: \n", prs(a)print "Number", x, "is on position", bs(prs(a), x), "in the list."`

_________________ Follow me on Twitter at @lucaciandrei Lucaci Andrei
"Tata Lor" Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 26
Location : Cluj-Napoca   Permissions in this forum:
You cannot reply to topics in this forum