2016-03-02 55 views
-2

我需要知道如何執行一些基本的列表操作,我們需要將其中一個算法顛倒過來,另一個我們需要拆分列表,並且它只需要僞代碼列表上的操作ADT

這裏是寫在混合算法

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

歡迎來到Stack Overflow!您可能想要查看[問]以瞭解您爲什麼被低估。通常情況下,如果問題更具體,並且包含迄今爲止嘗試的問題,問題會得到更好的答覆。 – APH

回答

-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