Q18Multiple correct6 Marks28 Apr 2024
Consider the following pseudocode for inserting an element into a sorted list in descending order. The pseudocode may have mistakes. Identify all such mistakes (if any).
```
Procedure SortedListInsert(L, x)
newList = []
inserted = True
foreach z in L{
if(not(inserted)){
if(x < z){
newList = newList ++ [x]
inserted = True
}
}
newList = [z] ++ newList
}
if(not(inserted)){
newList = newList ++ [x]
}
return(newList)
End SortedListInsert
```