Operations on a list


In this example I will use the list [A,B,C,D]. This list will be called demo

OperationExplanationDemoList after operationReturn
isEmptyTest to see if the list is emptydemo.isEmpty()[A,B,C,D]False
appendAppends onto the listdemo.append(E)[A,B,C,D,E]Null
removeRemove a item from the listdemo.remove(A)[B,C,D]Null
searchSearches for an item and returns the index of that itemdemo.search(C)[A,B,C,D]2
lengthGet the length of the listdemo.length()[A,B,C,D]4
insertInsert an item into the list with a given positon.demo.insert(X,1)[A,X,B,C,D]Null
popRemove the last item off the list and return that item.demo.pop()[A,B,C]D
pop with positionSimilar to remove but returns the removed item.demo.pop(1)[A,C,D]B