Ninth day learning data structure (a) (including the number of learning guidelines)

Guidelines to learn: how to look about the documentation, namely: What are the interface functions to use and so on.  

For a heap this kind of thing, now that is: to write one thing to achieve.

For priorityQueue can heap implementation, there should be a corresponding already written, you can call interface

 

For heap has been done, then look priorityQueue, then do leetcode after reading the title

 

For the priority queue understanding:

It was originally queue: FIFO results

As for the priority queue: vip achieve a functional, first-out may not be advanced, with high priority node first out.

This is the priority queue introduction and effect.

And heap relationship: heap are maximum and minimum can be placed at the root, and therefore can be used to achieve priorityQueue heap as priorityqueue underlying storage.

 

 

 

First learned: priorityQueue in java inside, can be used directly, import java.util can be used.

Then if one of the add function remove function will peek functions are slightly used.

 

For comparison priorityQueue, and learn a lot:

1. The number in indicating the priority order, then the default, which is the subject of priority.

For example: 8 and 15, it will be recognized 8 that higher priority.

 

 

2. If the comparator wrote, defining a new comparison logic, observe the following points:

(1) compared to the connotation wrote, override compare function.

(2) Remember, the first parameter is their own, and the second parameter represents the others. Others own less than minus 0, then considered a higher priority. (And compareTo contrary, compareTo, then, if less than 0, that is smaller)

Constructor (3) into priorityQueue the comparator, the logic configured to tell priorityqueue

 

 

If a custom class, then it needs to tell the compare logic and a field comparison, if you want to be small in accordance with the preceding row of logic, it should be the front - rear (corresponding fields are subtracted Comparative)

If the big front row, then the back - front

 

For the connotation static function:

static function can not access non-static objects.

The reason: Each non-static function, passing a default this field therein.

Because static functions can not have this object, so I did not know what the object is accessed.

 

 

 

 

Usage: to create the current class object, go call a non-static member.

For example here is create an instance of the object with the Main

If you here: do not create an instance of an object that Main directly call a non-static member, it is wrong, as follows:

 

 First, in this object, go call the appropriate function of the object.

 

 

 

 

 

 

key: this matter into the internal function, for the Add (8) of this matter, it means that this object x is 8, namely: x corresponding to the first object.

Namely: compare writing is a method of comparing two numbers, but when actually called, the first argument is this, is to take themselves to compare and newly added.

Well and I think the same, less than 0 proved to be relatively small. 

W Comparator time, if less than the required number of higher priority, then someone else is using your own cut.

If you need a large number of high priority, then cut himself with others.

 

It will present how to call priorityqueue, how to write your own comparator, how to do new class of comparators.

Then talk about how they use the heap to achieve priorityqueue

 

 This is the structure: heap implementation is the inner array, then if the underlying structure of the heap priorityqueue

For the queue, it is as an interface, priorityqueue is achieved for the queue.

 

If a single file structure:

 

 

 

 

Method definition is the same, but integrated in a file inside of it.

 

For this priorityQueue write their own words, if it is minHeap, then the priority is small, if it is maxheap, it is a big priority

The reason: with its storage structure related, minheap are small on top, maxheap is big on it.

 

And then minheap and maxheap, except that: different siftUp, siftDwon time conditions, is greater or less than the termination time siftUp different.

 

 Namely: the difference between minheap and maxheap is here only. Several symbol problem.

Then write about leetcode According to this topic, the other from the blog post.

 

Guess you like

Origin www.cnblogs.com/startFrom0/p/12637517.html