[Unity] [Heap sort] the process of dynamically demonstrating heap sequencing with unity

Source: Internet
Author: User

[Unity] [Heap sort] the process of dynamically demonstrating heap sequencing with unity

How Heap Sort Works

Recently, a program that uses Unity3d to dynamically demonstrate the heap sequencing process has been done.

I ' ve made this heap sort demo to show how heap sort works recently.

(Demo)

A picture of the thousand words.

A picture paints a thousand words.

You can view the full animated GIF here. There is no such large gif in the blog park.

Link: http://pan.baidu.com/s/1kT051pd Password: zpy3

You can check out the whole gifs here. The blog don ' t support a big gif like it.

LINK:HTTP://PAN.BAIDU.COM/S/1KT051PD Password:zpy3

Heap sort (heap sort)

Heap sorting always establishes such a binary tree: its parent node is always greater than its child nodes.

Step 1:the first step of heap sort is to build a binary tree in which the parent node's value is always greater than its Children nodes ' value.

Build the heap first.

It ' s called Building the heap.

Each wheel swaps the root node with the last node, and then builds the rest of the heap.

Step 2:ater that, we swaps the root node and the last node, hasn ' t been swapped yet.

Step 3:build The heap again like in step 1.

Step 4:if Not all nodes is swapped in Step 2, goto STEP2. Otherwise goto Step 5.

Step 5:the Heap sort is finished.

1         Private Static voidHeapsortascending1<t> ( ThisIlist<t>arr)2             wheret:icomparable3         {4              for(inti = arr. Count/2-1; I >=0; i--)5             {6 arr. HeapAdjustAscending1 (i, arr.) Count);7             }8              for(inti = arr. Count-1; i >0; i--)9             {TenT temp = arr[0]; Onearr[0] =Arr[i]; AArr[i] =temp; -Arr. HeapAdjustAscending1 (0, i); -             } the         } -         Private Static voidHeapadjustascending1<t> ( ThisIlist<t> arr,intNonleafnodetobeadjusted,intunrangedcount) -             wheret:icomparable -         { +             intLeftchild = nonleafnodetobeadjusted *2+1; -             intRightchild = nonleafnodetobeadjusted *2+2; +             intMax =nonleafnodetobeadjusted; A             if(Nonleafnodetobeadjusted < Unrangedcount/2)//Non-leaf node at             { -                 if(Leftchild < Unrangedcount && Arr[leftchild]. CompareTo (Arr[max]) >0) -{max =Leftchild;} -                 if(Rightchild < Unrangedcount && Arr[rightchild]. CompareTo (Arr[max]) >0) -{max =Rightchild;} -                 if(max!=nonleafnodetobeadjusted) in                 { -T temp =Arr[max]; toArr[max] =arr[nonleafnodetobeadjusted]; +Arr[nonleafnodetobeadjusted] =temp; - arr. HeapAdjustAscending1 (max, unrangedcount); the                 } *             } $}
Heap Sort Download (Download)

You can download Android apk here. If you need source code, please donate 10 yuan and leave your e-mail.

You can download the howheapsortworks.apk for Android below here.

Link: Http://pan.baidu.com/s/1c0GYIaO Password: Hlvi

Link:http://pan.baidu.com/s/1c0gyiao Password:hlvi

If you want the source code, please kindly donate¥10 and leave your email adress:)

[Unity] [Heap sort] the process of dynamically demonstrating heap sequencing with unity

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.