[number2].item); Linkedlist.removeafter (Nodes[number2]); Stdout.println ("Remove sucess after node" +Nodes[number2].item); Stdout.println ("The list whose first node is:" + nodes[0].item); STDOUT.PRINTLN (list); stdout.printf ("The nodes after a null node would be removed\n"); Linkedlist.removeafter (NULL); Stdout.println ("Remove sucess after a null node"); Stdout.println ("The list whose first node is:" + nodes[0].item); STDOUT.PRINTLN (list); }}Result output:
improvement)Algorithm: asks if a set of n numbers contains and is 2 elements of X (need to support C99 standard)BOOLSumX (intA[],intNintx) { intlength, complement[n]; MergeSort (A,0, N-1); Length=deduplication (A, n); Xcomplement (A, complement, length, x); returnMergesearch (A, complement, length);}BOOLMergesearch (intA[],intB[],intN) { intI, J; for(i=0, j=n-1; I0 a[i]!=B[j];) if(A[i] ; Elsej--; returnI0;}voidXcomplement (intA[],intAcomplement[],intNintx) { inti; for(i=0; ia[i];}
2.2-1:Θ (N3)2.2-2: Insert sortvoidSelectionsort (intA[],intN) { intI, J, K, Key; for(i=0; i1; i++) {k=i; for(j=i+1; j) if(A[k] > a[j]) k =J; if(k! =i) {key=A[k]; A[K]=A[i]; A[i]=key; } }}View CodeBest case: Θ (n2)Worst case: Θ (n2)2.2-3: Linear sortingAverage situation: N/2Worst case: N2.2-4:Method: First to determine whether the completion criteria have been met, in the best case, the program can have a better effect.Introduction to Algori
1counting-SORT2 (a,k)2 Let C[0..K] is a new array3 fori =0 to K4c[i]=05 fori = 1To A.length6C[a[i]] = c[a[i]]+17 fori = 1to K8C[i] = C[i] + c[i-1]9 fori = a.length Downto 1Ten whileI C[a[i]) One Exchagnge A[i] with A[j] AC[A[J]] = c[a[j]]-1#include Introduction to Algorithms third Edition study questions 8-2.E
is n, the loop is invariant, that is, either the subscript I (a[i] = = v) is taken in the array n, or it is not found (v = NIL). Then add an element, make the scale of n+1, easy to know, the size of n since the establishment (can get a useful nature, conclusion), scale n+1 at most one time equal judgment (that is, in the original array does not take the case of I), and finally can obtain useful conclusions. The iteration (in this case, size + 1) will keep the loop invariant.Termination: Finall
[] arr = {2, 5, 8, 3, 6}; Selectionsort (arr); } Public Static voidSelectionsort (int[] arr) { for(inti=0;i//The outer loop controls which position the number is compared to the number in the back for(intj=i+1;j//the inner loop controls how many times this number needs to be compared to the subsequent number. if(Arr[i]>arr[j]) {// //This condition is guaranteed to be arranged from small to large, and vice versa from large to small intt
Requirements:As written, each loop iteration in the List-search ' procedure requires the tests:One for X≠l.nil and one for x.key≠k. Show How to eliminate the test forX≠l.nil in each iteration.Solution:The key is to set Sentinel Sentinel's key value to K prior to the start of the while loop, so that the while loop will terminate if the query succeeds in the listPseudo codeList-search ' (L, K)1 L.nil.key = k2 x = L.nil.next3 while X.key≠k4 x = X.next5 if x = = L.nil6 L.nil.key = Nil7 return XIntro
this optimal step size of the smaller array109 //var Steparr = [1031612713, 217378076, 45806244, 9651787, 2034035, 428481, 90358, 19001, 4025, 836, 182, 34, 9, 1]//for large The step selection of an array the vari = 0;111 varSteparrlength =steparr.length; the varLen =Array.Length;113 varLen2 = parseint (LEN/2); the the for(; i ) { the if(Steparr[i] >len2) {117 Continue;118 }119 - Stepsort (Steparr[i]);121 }122 123 //Sort a step124
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.