我目前正在尝试学习java Arrays.binarySearch,并参阅下面的Oracle doc:
gluPerspective(45, 1, 0.1, 50.0)
def sin(x): return math.sin(math.radians(x))
def cos(x): return math.cos(math.radians(x))
def drawTriangle():
glBegin(GL_TRIANGLES)
glVertex3f(0,0,0)
glVertex3f(0,1,0)
glVertex3f(1,0,0)
glEnd()
def goto(x,y,z,pitch,yaw,roll):
glLoadIdentity()
glRotatef(pitch,1,0,0)
glRotatef(yaw,0,1,0)
glRotatef(roll,0,0,1)
glTranslatef(-x,-y,-z)
x=0
y=0
z=5
pitch=0
yaw=0
roll=0
while True:
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
pygame.event.get()
if pygame.key.get_pressed()[pygame.K_w]:
z+=.1
elif pygame.key.get_pressed()[pygame.K_s]:
z-=.1
elif pygame.key.get_pressed()[pygame.K_a]:
x+=.1
elif pygame.key.get_pressed()[pygame.K_d]:
x-=.1
if pygame.key.get_pressed()[pygame.K_UP]:
yaw+=1
elif pygame.key.get_pressed()[pygame.K_DOWN]:
yaw-=1
elif pygame.key.get_pressed()[pygame.K_LEFT]:
pitch+=1
elif pygame.key.get_pressed()[pygame.K_RIGHT]:
pitch-=1
goto(x,y,z,pitch,yaw,roll)
drawTriangle()
pygame.display.flip()
pygame.time.wait(20)
os.system("cls")
返回:
搜索键的索引,如果它包含在数组中 指定范围;否则,( - (插入点) - 1)**
如果没有找到,我不知道为什么返回 - (插入点) - 1在这里?为什么不返回-1或 - (插入点)?什么是 - (插入点) - 1?
的想法答案 0 :(得分:2)
因为它提供了原本无法获得的额外信息。因此需要 - 插入点来传达该信息。问题是,插入点可能为0.那么如何区分0处的匹配和插入点0处的失败?你必须-1才能使这种区分成为可能。