Untitled

mail@pastecode.io avatar
unknown
python
a year ago
697 B
3
Indexable
Never
queue = []
def F(x, y):
    global queue
    for i in range(len(queue) - 1):
        if (queue[i] < x < queue[i + 1] or queue[i] > x > queue[i + 1]) and ((y - x > 0) == (queue[i+1] - queue[i] > 0)):
            queue.insert(i+1, x)
            x_i = i + 1
            break
    else:
        queue.append(x)
        x_i = len(queue)  - 1
    
    for i in range(x_i, len(queue) - 1):
        if (queue[i] < y < queue[i + 1] or queue[i] > y > queue[i + 1]) and ((y - x > 0) == (queue[i+1] - queue[i] > 0)):
            queue.insert(i+1, y)
            break
    else:
        queue.append(y)
    print("current queue: ", *queue, sep = " ")
F(5, 10)
F(7, 2)
F(6, 9)
print("queue: ", *queue, sep=" ")