{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Homework 6 - listA.next = merge(listA.next listB return...

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

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){

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

View Full Document
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

{[ snackBarMessage ]}