 View full slide show From Idea to Solution for (int i = list.length - 1; i >= 1; i--) { select the largest element in list[0..i]; swap the largest with list[i], if necessary; // list[i] is in place. The next iteration applies on list[0..i-1] } list list list list ... list list list list list ... list list list list ... list list list list ... list list list ... list Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved. 0136012671 88
View full slide show View full slide show View full slide show View full slide show View full slide show Comparing the Three Implementations (cont.)  Storage  Linked-list implementations require more storage due to the extra space required for the links  Each node for a single-linked list stores two references (one for the data, one for the link)  Each node for a double-linked list stores three references (one for the data, two for the links)    A double-linked list requires 1.5 times the storage of a single-linked list A circular array that is filled to capacity requires half the storage of a single-linked list to store the same number of elements, but a recently reallocated circular array is half empty, and requires the same storage as a single-linked list
View full slide show View full slide show From Idea to Solution for (int i = 1; i < list.length; i++) { insert list[i] into a sorted sublist list[0..i-1] so that list[0..i] is sorted } list list list list list list list list list list list list list list ...
View full slide show Trace of the Example (diff ‘x ‘(+ ‘(* 2 x) 1)) = (list ‘+ (diff ‘x ‘(*2 x)) (diff ‘x 1)) = (list ‘+ (list ‘+ (list ‘* 2 (diff ‘x ‘x)) (list ‘* x (diff ‘x 2))) (diff ‘x 1)) = (list ‘+ (list ‘+ (list ‘* 2 1) (list ‘* x (diff ‘x 2))) (diff ‘x 1)) = (list ‘+ (list ‘+ ‘(* 2 1) (list ‘* x (diff ‘x 2))) (diff ‘x 1)) = (list ‘+ (list ‘+ ‘(* 2 1) (list ‘* x (diff ‘x 2))) (diff ‘x 1)) = (list ‘+ (list ‘+ ‘(* 2 1) (list ‘* x 0)) 0) = ‘(+ (+ (* 2 1) (* x 0)) 0) Copyright © 2006 The McGraw-Hill Companies, Inc.
View full slide show