Beispiel #1
0
def get_max_index(a):
  v=0
  j=-1
  i=0
  while i <= len(a)-1:
    if (j == -1 or v < a[i]):
      v=a[i]
      j=i
    i+=1
  return j
Beispiel #2
0
def get_min_index(a):
    v = 0
    j = -1
    i = 0
    while i < len(a):
        if (j == -1 or v > a[i]):
            v = a[i]
            j = i
        i += 1
    return j
Beispiel #3
0
def get_min_index(a):
	v=0
	j=-1
	i=0
	while i < len(a):
		if (j == -1 or v > a[i]): 
			v=a[i]
			j=i
		i+=1
	return j
Beispiel #4
0
def oddSort(x, length=none):
    l = length
    if (length is none):
        l = len(x)
    sorted = false
    while not sorted:
        sorted = true
        i = 0
        while i < len(x):
            if x[i] > x[i + 1]:
                temp = x[i]
                x[i] = x[i + 1]
                x[i + 1] = temp
                sorted = false
            i += 2
        i = 1
        while i < len(x) - 1:
            if x[i] > x[i + 1]:
                temp = x[i]
                x[i] = x[i + 1]
                x[i + 1] = temp
                sorted = false
            i += 2
Beispiel #5
0
def oddSort(x, length=none):
  l=length
  if (length is none):
    l=len(x)
  sorted=false
  while not sorted:
    sorted=true
    i=0
    while i<len(x):
        if x[i] > x[i+1]:
            temp= x[i]
            x[i]=x[i+1]
            x[i+1] = temp
            sorted=false
        i+=2
    i=1
    while i<len(x)-1:
        if x[i] > x[i+1]:
            temp= x[i]
            x[i]=x[i+1]
            x[i+1] = temp
            sorted=false
        i+=2
Beispiel #6
0
Simple odd-even sort
*/

from util import *
from random import randrange
from array import len, array

x=array(100)
for i in range(99):
	x[i]=randrange(100)

sorted=false
while not sorted:
	sorted=true
	i=0
	while i<len(x):
		if x[i] > x[i+1]:
			temp= x[i]
			x[i]=x[i+1]
			x[i+1] = temp
			sorted=false
		i+=2
	i=1
	while i<len(x)-1:
		if x[i] > x[i+1]:
			temp= x[i]
			x[i]=x[i+1]
			x[i+1] = temp
			sorted=false
		i+=2