Homework 6 - listA.next = merge (listA.next, listB); return...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
public static int [] counting_sort( int [] arrayA, int counter) { int [] arrayC = new int [counter+1]; int [] arrayB = new int [arrayA.length]; for ( int i=0; i<=counter; i++){ arrayC[i]=0; // make all elemtents 0 } for ( int j=0; j<arrayA.length; j++){ arrayC[arrayA[j]] = arrayC[arrayA[j]] + 1; } for ( int i=1; i<=counter; i++){ arrayC[i] += arrayC[i-1]; } for ( int j=arrayA.length-1; j>=0; j–-){ arrayB[arrayC[arrayA[j]]-1] = arrayA[j]; arrayC[arrayA[j]] = arrayC[arrayA[j]] - 1; } return arrayB; } // B) Efficiency of a counting sort - insertion sort O(n^2) - quick sort O(n^2) - counting sort O(n) // 9a // Recursion method public Node merge (Node listA, Node listB) { if (listA == null ) return listB; if (listB == null ) return listA; if (listA.data < listB.data){
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: listA.next = merge (listA.next, listB); return listA; } else { listB.next = merge (listA, listB.next); return listB; } } // Chapter 13 // #1 LList nameJustList = new LList(); for ( int i = nameList.getLength(); i <= 1; i--){ nameJustList.add(nameList.getEntry(i)); } // #2 // Client Level of the method public boolean addUniqueItem (Object obj){ for ( int i = 1; i <= nameList.getLength(); i++){ if (obj = nameList.getEntry(i)) return false ; } return true ; } // Using the Method on client level somewhere in main if (nameList.addUniqueItem(SomeObject)){ //I can use standard add method from the book (13.10) nameList.add(SomeObject) }...
View Full Document

This note was uploaded on 01/23/2012 for the course CS 111C taught by Professor Metzler during the Spring '11 term at City College of San Francisco.

Page1 / 2

Homework 6 - listA.next = merge (listA.next, listB); return...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online