Click to enter _ more _java thousand ask1. When the memory space of an array is allocatedAn array in Java is a data structure used to store the same data type, and once the initialization is complete, the space occupied is fixed, and the process of initializing it is the process of allocating the corresponding memory s
- 1, origin, destination, assist); move(origin, destination); hanoi(n - 1, assist, origin, destination); } } // Print the route of the movement private void move(char origin, char destination) { System.out.println("Direction:" + origin + "--->" + destination); } public static void main(String[] args) { Hanoi hanoi = new Hanoi(); hanoi.hanoi(6, ‘A‘, ‘B‘, ‘C‘); }}The factorial problem of n?? The problem seems very simple, for the
Java data structure and algorithm parsing (13)--Priority queue
In many applications, we usually need to deal with the processing object according to the priority situation, such as dealing with the highest priority object first, and then processing the object of the high level. The simplest example is when you play a game on a mobile phone, and if there is a cal
, as follows:An example diagram of the same deletion is as follows:The following is the code I implemented in Java, the main function is to implement only insert and delete operations:Package com.phn.datestructure;/** * @author Pan Hainan * @Email [emailprotected] * @TODO static linked list * @date July 19, 2015 */public Class FostaticlistIn the example diagram of a delete, please contact my code to doFirst, write a test method.public static void m
of "hashing" makes HashMap's query more efficient than any other data structure. However, as we all know, the best hash is that each element in the array is a chain of only one node, that is, each subscript in the array corresponds to only one node, so that the HashMap query efficiency can be guaranteed to reach the highest. Of course, this situation is difficult to achieve, but HashMap provides us with a
specified length *@paramsize*/@SuppressWarnings ("Unchecked") PublicCirqueue (intsize) {a= (e[]) (NewObject[size]); Front=0; Rear=0; } /*** Append an object to the tail of the queue *@paramobj *@returnreturns False if the queue is full, otherwise true *@authorwwx*/ Public Booleanenqueue (E obj) {if((rear+1)%a.length==front) { return false; }Else{A[rear]=obj; Rear= (rear+1)%a.length; return true; } } /*** Queue head out team *@return * @authorwwx*/ Pub
Data Structure tutorial (Java description) edited by Xu xiaokai-review abstract 04
Chapter 3 stack and queue
Stack sequential storage structure and operation implementation
Public class sequencestack implements stack {final int maxsize = 10; // assume that the initial length of the one-dimensional array of the storage
, it will be inserted into the front of the list, not only because it is convenient, but also because it often happens that the newly inserted element is most likely to be accessed soon. The following is a simple implementation of a hash table using the Detach link method:Import Java.util.iterator;import java.util.linkedlist;import Java.util.list;import Java.util.random;public class separatechaininghashtableExecution Result:-----0-----1 24-----25 2-----3-----4 27-----5-----6 29-----7-----8------
the loopfor (j=i-1;j>0;j--) {if (Array[0]array[j+1]=array[j];//the position of the element smaller than the Sentinel moves backwards}else{Break}}Code Lite version/*for (j=i-1;array[0]ARRAY[J+1]=ARRAY[J];}*/array[j+1]=array[0];//inserts the current element to be compared to the location found}}/*** Output array elements* @param array to display*/static void show (int [] array) {for (int i = 1; I System.out.print (array[i]+ "");}System.out.println ("\ n");}}This article is from the "Holding" blog
() {returnRemove (size-1); } /*** Delete an element in an array *@paramelement*/ Public voidRemoveelement (intElement) { //first determine if the element exists intindex =find (Element); if(Index! =-1) {remove (index); } } //gets the element that corresponds to the index intGetintindex) { if(Index size) { Throw NewIllegalArgumentException ("Get fail, index is illegal"); } returnData[index]; } //change the value of the corresponding eleme
(); } stack = new object[ initsize]; index = -1; }
/*** Out Stack operation** @return Stack Top Object*/Public synchronized E Pop () {if (!isempty ()) {E temp = peek ();stack[index--] = null;return temp;}return null;}
/*** Into stack operation** @param obj* Waiting for the object to stack*/Public synchronized void push (E obj) {if (Isfull ()) {object[] temp = stack;If the stack is full, create a stack with twice times the current stack spacestack = new object[2 * Stack.length];Syste
the number of laps②-① get the following formula(n-n) * (x+y) = m;Next, the ① will be put into the formula(n-n) * (x+y) = k+x+n* (x+y);here The X+y ring length is a fixed value. Assuming that the ring length is M(n-n) *m = k+x+n*m; ----> deformation obtained k+x = (n-2*n) *m;Formula : K+x = (n-2*n) *msince we are designed to be O-cycle linked list, then the start is the loop point B, then (n-2*n) *m = 0.N = 2*n; The number of rings around a fast-speed hand is twice times that of the latter, and
are interchanged.Build a large top heap or small top heap3. Sorting complete View Code Ix. summarize and compare the advantages and disadvantages of various sorting algorithms 1, note that the stability of the order means: example.Before sorting: 5,6 (1), 1,4,3,6 (2), (first 6 before the second 6)After sorting: If the sorted result is 1,2,3,4,5,6 (1), 6 (2) Then it is said that the sorting algorithm is stable, and vice versa is un
First, the summary Two forks the search tree is either an empty tree or a two-prong tree with the following properties:(1The Joz tree is not empty, then the value of all nodes on the left subtree is less than the value of its root node;(2If the right subtree is not empty, the value of all nodes on the right subtree is greater than or equal to the value of its root node;(3the left and right sub-trees are also two-fork sorting trees;(4) There are no nodes with key values equal. The two-fork sear
First, Introduction: Want to give ArrayList sort but found no sorting method? You have two options:1, swap with treeset;2. Use Collection.sort (listSecond, to expand the analysis of several major Java data structure and sorting methods:
LinkedList
Efficient operation of elements
TreeSet
No repetition, orderly
Ha
("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;
Data Structure-heap implementation priority queue (java)
The queue features FIFO. Generally, queues are similar to queuing for shopping. Everyone is very orderly. the first person in the queue buys something first. The priority queue is different. It does not follow the first-in-first-out rule, but is extracted first with the highest priority based on the priorit
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.