Skip to content

Commit

Permalink
Site updated: 2017-07-14 13:22:40
Browse files Browse the repository at this point in the history
  • Loading branch information
LingJiangXie committed Jul 14, 2017
1 parent 3968cb9 commit 991ba48
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 757 deletions.
95 changes: 7 additions & 88 deletions 2017/05/13/markdown 测试/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
<link rel="shortcut icon" href="/favicon.ico">
<link rel="alternate" href="/atom.xml" title="领江的小博客">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="markdown 测试设置代码块```12 package binaryheap; public class BinaryHeap { private static final int DEFAULT_CAPACITY=10; public int currentSize; public int [] array; private void percolateDown(int h">
<meta name="description" content="markdown 测试设置代码块1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889package binaryh">
<meta name="keywords" content="YAYA,Hexo">
<meta property="og:type" content="article">
<meta property="og:title" content="markdown测试">
<meta property="og:url" content="http://yoursite.com/2017/05/13/markdown 测试/index.html">
<meta property="og:site_name" content="领江的小博客">
<meta property="og:description" content="markdown 测试设置代码块```12 package binaryheap; public class BinaryHeap { private static final int DEFAULT_CAPACITY=10; public int currentSize; public int [] array; private void percolateDown(int h">
<meta property="og:updated_time" content="2017-07-14T05:19:15.412Z">
<meta property="og:description" content="markdown 测试设置代码块1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889package binaryh">
<meta property="og:updated_time" content="2017-07-14T05:22:20.843Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="markdown测试">
<meta name="twitter:description" content="markdown 测试设置代码块```12 package binaryheap; public class BinaryHeap { private static final int DEFAULT_CAPACITY=10; public int currentSize; public int [] array; private void percolateDown(int h">
<meta name="twitter:description" content="markdown 测试设置代码块1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889package binaryh">

<link href="https://fonts.googleapis.com/css?family=Inconsolata|Titillium+Web" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
Expand Down Expand Up @@ -143,93 +143,12 @@ <h2 class="title">

</section>

<section class="toc-wrapper"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#markdown-测试"><span class="toc-number">1.</span> <span class="toc-text">markdown 测试</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#设置代码块"><span class="toc-number">1.1.</span> <span class="toc-text">设置代码块</span></a></li></ol></li></ol></section>
<section class="toc-wrapper"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#markdown-测试"><span class="toc-number">1.</span> <span class="toc-text">markdown 测试</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#设置代码块"><span class="toc-number">1.1.</span> <span class="toc-text">设置代码块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#下一个"><span class="toc-number">1.2.</span> <span class="toc-text">下一个</span></a></li></ol></li></ol></section>

<section class="article typo">
<div class="article-entry" itemprop="articleBody">
<h2 id="markdown-测试"><a href="#markdown-测试" class="headerlink" title="markdown 测试"></a>markdown 测试</h2><h3 id="设置代码块"><a href="#设置代码块" class="headerlink" title="设置代码块"></a>设置代码块</h3><figure class="highlight plain"><figcaption><span>```</span></figcaption><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"></div><div class="line"></div></pre></td></tr></table></figure>
<p>package binaryheap;</p>
<p>public class BinaryHeap {<br> private static final int DEFAULT_CAPACITY=10;<br> public int currentSize;<br> public int [] array;</p>
<pre><code>private void percolateDown(int hole){
int child=0;
//tmp值是那个传入的最初要下沉的值
int tmp=array[hole];
//这个for循环,结束之后,hole要不就是最后一个,要不就满足了堆,(子树)根节点最小的特性
for(;hole*2&lt;=currentSize;hole=child){

child=hole*2;
if(child!=currentSize &amp;&amp; (array[child+1]&lt;array[child]) ) child++;
//如上的语句结束可以得到两个子节点中较小的那个
if(array[child]&lt;tmp){
array[hole]=array[child];
}else break;
//如上判断结束hole到了最终的位置
}
array[hole]=tmp;
}

private void buildHeap(){
//这里从currentSize/2这个位置(最后一个非叶节点)开始,直到根节点,不断下滤调整堆序。
for(int i= currentSize/2;i&gt;0;i--){
percolateDown(i);
}
}

public void enlarge(int newSize){
int [] tmp=new int[newSize];
for(int i=1;i&lt;=currentSize;i++){
tmp[i]=array[i];
}
array=tmp;

}

public BinaryHeap(int [] data){
//先依据传入的数组,建造无序堆,在调整成有序堆。
currentSize=data.length;
array=new int[(currentSize+2)*11/10];
int i=1;
for(int item : data) array[i++]=item;
buildHeap();
}

public void makeEmpty(){
currentSize=0;
}
public boolean isEmpty(){
return currentSize==0;
}
public int min(){
if(isEmpty()) {
System.out.println(&quot;堆为空!返回-1&quot;);
return -1;
}
else{
return array[1];
}
}
public int deleteMin(){
if(isEmpty()) {
System.out.println(&quot;堆为空!返回-1&quot;);
return -1;
}
int lastmin =min();
array[1]=array[currentSize--];
percolateDown(1);
return lastmin;
}
public void insert(int data){
//自动扩容
if(currentSize==array.length-1){
enlarge(array.length*2+1);
}
//上冒操作
int hole=++currentSize;
for(;hole&gt;1 &amp;&amp; data &lt; array[hole/2];hole/=2) array[hole]=array[hole/2];
array[hole]=data;
}
</code></pre><p>}</p>
<p>```</p>
<h2 id="markdown-测试"><a href="#markdown-测试" class="headerlink" title="markdown 测试"></a>markdown 测试</h2><h3 id="设置代码块"><a href="#设置代码块" class="headerlink" title="设置代码块"></a>设置代码块</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">package binaryheap;</div><div class="line"></div><div class="line">public class BinaryHeap &#123;</div><div class="line"> private static final int DEFAULT_CAPACITY=10;</div><div class="line"> public int currentSize;</div><div class="line"> public int [] array;</div><div class="line"> </div><div class="line"> private void percolateDown(int hole)&#123;</div><div class="line"> int child=0;</div><div class="line"> //tmp值是那个传入的最初要下沉的值</div><div class="line"> int tmp=array[hole];</div><div class="line"> //这个for循环,结束之后,hole要不就是最后一个,要不就满足了堆,(子树)根节点最小的特性</div><div class="line"> for(;hole*2&lt;=currentSize;hole=child)&#123;</div><div class="line"> </div><div class="line"> child=hole*2;</div><div class="line"> if(child!=currentSize &amp;&amp; (array[child+1]&lt;array[child]) ) child++;</div><div class="line"> //如上的语句结束可以得到两个子节点中较小的那个</div><div class="line"> if(array[child]&lt;tmp)&#123;</div><div class="line"> array[hole]=array[child];</div><div class="line"> &#125;else break;</div><div class="line"> //如上判断结束hole到了最终的位置</div><div class="line"> &#125;</div><div class="line"> array[hole]=tmp;</div><div class="line"> &#125;</div><div class="line"> </div><div class="line"> private void buildHeap()&#123;</div><div class="line"> //这里从currentSize/2这个位置(最后一个非叶节点)开始,直到根节点,不断下滤调整堆序。</div><div class="line"> for(int i= currentSize/2;i&gt;0;i--)&#123;</div><div class="line"> percolateDown(i);</div><div class="line"> &#125;</div><div class="line"> &#125;</div><div class="line"> </div><div class="line"> public void enlarge(int newSize)&#123;</div><div class="line"> int [] tmp=new int[newSize];</div><div class="line"> for(int i=1;i&lt;=currentSize;i++)&#123;</div><div class="line"> tmp[i]=array[i];</div><div class="line"> &#125;</div><div class="line"> array=tmp;</div><div class="line"> </div><div class="line"> &#125;</div><div class="line"> </div><div class="line"> public BinaryHeap(int [] data)&#123;</div><div class="line"> //先依据传入的数组,建造无序堆,在调整成有序堆。</div><div class="line"> currentSize=data.length;</div><div class="line"> array=new int[(currentSize+2)*11/10];</div><div class="line"> int i=1;</div><div class="line"> for(int item : data) array[i++]=item;</div><div class="line"> buildHeap();</div><div class="line"> &#125;</div><div class="line"> </div><div class="line"> public void makeEmpty()&#123;</div><div class="line"> currentSize=0;</div><div class="line"> &#125;</div><div class="line"> public boolean isEmpty()&#123;</div><div class="line"> return currentSize==0;</div><div class="line"> &#125;</div><div class="line"> public int min()&#123;</div><div class="line"> if(isEmpty()) &#123;</div><div class="line"> System.out.println(&quot;堆为空!返回-1&quot;);</div><div class="line"> return -1;</div><div class="line"> &#125;</div><div class="line"> else&#123;</div><div class="line"> return array[1];</div><div class="line"> &#125;</div><div class="line"> &#125;</div><div class="line"> public int deleteMin()&#123;</div><div class="line"> if(isEmpty()) &#123;</div><div class="line"> System.out.println(&quot;堆为空!返回-1&quot;);</div><div class="line"> return -1;</div><div class="line"> &#125;</div><div class="line"> int lastmin =min();</div><div class="line"> array[1]=array[currentSize--];</div><div class="line"> percolateDown(1);</div><div class="line"> return lastmin;</div><div class="line"> &#125;</div><div class="line"> public void insert(int data)&#123;</div><div class="line"> //自动扩容</div><div class="line"> if(currentSize==array.length-1)&#123;</div><div class="line"> enlarge(array.length*2+1);</div><div class="line"> &#125;</div><div class="line"> //上冒操作</div><div class="line"> int hole=++currentSize;</div><div class="line"> for(;hole&gt;1 &amp;&amp; data &lt; array[hole/2];hole/=2) array[hole]=array[hole/2];</div><div class="line"> array[hole]=data;</div><div class="line"> &#125;</div><div class="line"> </div><div class="line"> </div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="下一个"><a href="#下一个" class="headerlink" title="下一个"></a>下一个</h3><p>其实啥都目有!</p>

</div>

Expand Down
Loading

0 comments on commit 991ba48

Please sign in to comment.