Write a pseudocode function swap(aList, i, j)that interchanges the itemscurrently in positions i and j of a list. Define the function in terms of the ADT list operations,so that it is independent of any particular implementation of the list. Assume that the list, infact, has items at positions i and j. What impact does this assumption have on your solution?

What will be an ideal response?

```
// Swaps the i-th and j-th items in the list aList.
swap(aList:List, i:integer, j:integer): void
{
//Copy the i-th and j-th items.
ithItem = aList.getEntry(i)
jthItem = aList.getEntry(j)
//Replace the i-th item with the j-th item.
aList.remove(i)
aList.insert(i, jthItem)
//Replace thej-th item with the i-th item.
aList.remove(j)
aList.insert(j, ithItem)
}

```

Computer Science & Information Technology

You might also like to view...

Which of the following is NOT a type of section break in Word 2010?

A) Next Page B) Continuous C) Even Page D) Last Page

Computer Science & Information Technology

Given a class named Animals and a class variable named ducky which will reference an Animals object, which is the correct way, using the textbook's pseudocode, to create an Animals object?

a. Set ducky = Animals() b. Set Animals = New ducky() c. Set ducky = New Animals() d. Set ducky = New Animals object

Computer Science & Information Technology