Solutions Manual for Data Structures And Algorithm Analysis In Java 3rd Edition by Weiss

Page 1

Solutions Manual for Data Structures And Algorithm Analysis In Java 3rd Edition by Weiss Full Download: https://downloadlink.org/p/solutions-manual-for-data-structures-and-algorithm-analysis-in-java-3rd-edition-by-wei

CHAPTER 3

Lists, Stacks, and Queues 3.1

public static <AnyType> void printLots(List<AnyType> L, List<Integer> P) { Iterator<AnyType> iterL = L.iterator(); Iterator<Integer> iterP = P.iterator(); AnyType itemL=null; Integer itemP=0; int start = 0; while ( iterL.hasNext() && iterP.hasNext() ) { itemP = iterP.next(); System.out.println("Looking for position " + itemP); while ( start < itemP && iterL.hasNext() ) { start++; itemL = iterL.next(); } System.out.println( itemL ); } }

3.2

(a) For singly linked lists:

// beforeP is the cell before the two adjacent cells that are to be swapped. // Error checks are omitted for clarity. public static void swapWithNext( Node beforep ) { Node p, afterp; p = beforep.next; afterp = p.next;

// Both p and afterp assumed not null.

p.next = afterp.next; beforep.next = afterp; afterp.next = p; } (b) For doubly linked lists:

// p and afterp are cells to be switched.

Error checks as before.

Š2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.

Full download all chapters instantly please go to Solutions Manual, Test Bank site: TestBankLive.com


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.