This is a set of practice questions. Feel free to work on these questions, and to ask questions if you face any difficulties in coming up with answers. While collaboration with others on the graded homework is strictly prohibited, you are free to work on these practice questions together with other people.
Since they are practice questions, you do not have to, and should not, submit answers to these questions on Blackboard. These questions will not be considered in any way towards your course grade. At the same time, based on the instructor's experience, individuals spending substantial and systematic effort in answering these practice questions by themselves tend to significantly improve their overall class performance.
The new functions that you need to implement (with constant running time) are:
Write a function that moves the largest item on a given list to be the final node on the list.
Write a function that moves the smallest item on a given list to be the first node on the list.
Write a function that rearranges a linked list to put the nodes in even positions after the nodes in odd positions in the list, preserving the relative order of both the evens and the odds.
Write a function that takes as arguments a linked list and two nodes T and U, and that exchanges the positions of the nodes AFTER the two given links T and U.
Write a function that takes two arguments, the first argument being a list, and the second argument being a function that takes a link as an argument. The function should remove all items on the given list for which the function returns a nonzero value.
Write a function void removeEvens(list A) that removes the nodes in even positions (the zeroth, second, fourth, sixth, and so forth) of list A. Remember, the first element of the list is considered to be at position 0.
Suppose that you have a finite set of nodes with no null pointers (each node refers to itself or to some other node in the set). Prove that you ultimately get into a cycle if you start at any given node and follow links.
Under the conditions of the previous task, write a function that, given a link to a node, finds the number of different nodes that it ultimately reaches by following links from that node, without modifying any nodes. Do not use more than a constant amount of extra memory space.
Under the conditions of the previous task, write a method that determines whether or not two given links, if followed, eventually end up on the same cycle.
Back to the list of assignments.