-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtradional.py
More file actions
30 lines (27 loc) · 914 Bytes
/
tradional.py
File metadata and controls
30 lines (27 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def FindPos(AR,item):
size=len(AR)
if item<AR[0]: #
return 0
else:
pos=-1 #
for i in range(size-1):
if(AR[i]<=item and item<AR[i+1]): #
pos=i+1 #
break
if(pos==-1 and i<=size-1): #
pos=size
return pos
def shift(AR,pos):
AR.append(None) #[10, 20, 30, 50, 60, 70, None]
size=len(AR)
i=size-1 #i=6
while i>=pos: #6>=4
AR[i]=AR[i-1] #[10, 20, 30, 50, 50, 60, 70]
i=i-1
#main
lst=[10,20,30,50,60,70]
item=40
position=FindPos(lst,item)
shift(lst,position)
lst[position]=item
print(lst)