; 1){ - if(Peoples[index]) { incount++; - if(Count = = 3){ toPeoples[index] =false; +Count=0; -leftcount--;//minus 1 for the rest of the population. the } * } $ Panax Notoginseng //put the element under the label -index++; the + //If you have counted to the end of the array, start the number A if(Index > Len-1){ theindex = 0; + } - } $ $ for(i
Some small algorithms are of the Java version, and a large number of questions on the network are aimed at C ++. Therefore, Java implementation is rare, but they are the basis of the test,
The implementation is the same. You can broaden your thinking and be helpful.
/*** 1 hop steps* Question: there are N levels in a step. If you can skip 1 level at a time, you
found to be less than or equal to the number of small points in the score bounds, then Exchange at if(Ltemp rtemp) { -t =Arr[ltemp]; -Arr[ltemp] =Arr[rtemp]; -Arr[rtemp] =T; ---rtemp; -++ltemp; in } - if(Ltemp = =rtemp) { toltemp++; + } - System.out.println (arrays.tostring (arr)); the if(Left rtemp) { *QuickSort (arr, left, ltemp-1); $ }Panax Notoginseng if(Ltemp Right ) { -QuickSort (arr, rtemp + 1, right); th
Java uses several classic algorithms to sort arrays.
Sort arrays in Java
Package com. souvc. hibernate. exp; public class MySort {/*** Method Name: main
read (char[] c, int offset, int length)Close () The basic method of writervoid Write ()void Write (char[] c)void Write (char[] c, int offset, int length)Write a string directly out, inside the string there is a method S.tochararray (), check APIvoid Write (String s)void Write (String s, int offset, int length)Close ()Flush ()File stream (byte stream, character stream)Buffered streamsConvert Stream---> byte-characterData Flow---> Eight data typesPrint Stream--->system.out.println ();Object Flow
points to a smaller element than the pivot element. If I is smaller than J, then exchange these two elements, that is, I point to the large element (relative to the pivot element) to the right of the array, J points to the small element to the left of the array, and then I and J continue to move. If I is greater than J, the description has moved to the end, at this point I left are smaller than the pivot element, I the right side (including i) are larger than the pivot element. Finally, the ele
List operation code is small but more error-prone, is more suitable for the interview place.
Code implementation
/** * Source Name: Mylinklist.java * Date: 2014-09-05 * program function: Java list operation * Copyright: [emailprotected] * A2bgeek */import Java.util.Sta Ck;public class Mylinklist {class Linknode"Data structures and Algorithms" Java l
--){ //K Save the node being judged intk=i; //If the child node of the current K-node exists while(k*2+1LastIndex) { //index of the left child node of the K-node intBiggerindex=2*k+1; //if Biggerindex is less than lastindex, that is, the right child node of the K node represented by biggerindex+1 exists if(biggerindexLastIndex) { //If the value of the right child node is large i
environment, the internal loop of the keyword Index program contains a large number of operations, which are much larger than the internal loops of a quick sort or merge sort algorithm. So the linear time overhead of the cardinality sort is not actually much smaller than the time overhead of fast sorting. And because the sorting code extraction algorithm based on the base sort is affected by the operating system and the ordering element, its adaptability is far less than that of ordinary compar
("Lookup data does not exist"); the return NULL; the } + -System.out.println ("Find successful, data is:" + This. list[p]); the return This. list[p];Bayi } the the //Sequential Table Size - Public intSizeOf () { - return This. Listlen; the } the the Public voidPrint () { theSystem.out.print ("["); - for(inti = 0; I This. list.length; i++) { theSystem.out.print ( This. List[i]); the if(I This. list.length-1) {
Quick Sort is an improvement to the bubbling sort, with an average time complexity of O (NLOGN)Importjava.util.Arrays;ImportJava.util.Scanner; Public classtest02{ Public Static voidMain (string[] args) {intn = 1; while(n! = 0) {Scanner Scanner=NewScanner (system.in); N=Scanner.nextint (); intS[] =New int[n]; for(inti = 0; I ) {S[i]=Scanner.nextint (); } sort (S,0, N-1); System.out.println (arrays.tostring (s)); } } Public Static voidSortint[] s,intLowintHigh ) { intleft =Low ;
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.