我需要知道如何为我们需要的一个算法执行一些基本列表操作来反转列表,另一个我们需要拆分列表,它只需要在伪代码中
以下是算法
Algorithm reverse (rList)
Pre: rList :: refToList
Post: order of the the elements in rList are reversed
Return: nothing
Algorithm split(rList)
Pre: rList :: refToList
Post: rList keeps half of its elements, creates new list for the other half
Return: a new refToList containing the other elements
答案 0 :(得分:-1)
reverse(list):
if length(list)==0:
return nothing
else:
reversedList = new list()
for i=length(list) i>=0 i--:
reversedList.add(list[i])
return reversedList
用混合的javish和pythonish伪代码编写 KEK