C Language Implementation Push sort

Source: Internet
Author: User

KeyPoint: Find the key parent node

The fastest way to find the largest single thread

#include "stdlib.h" #include "stdio.h" void Findmax (int *arr, int size) {int totparent = SIZE/2-1;for (; Totparent >= 0;totparent--) {int parent = Totparent;int Child = 2 * totparent + 1;if (Child < size-1 && Arr[child] < arr [child + 1]) {child++;} if (Arr[parent] < Arr[child]) {int tmp = Arr[child];arr[child] = arr[parent];arr[parent] = tmp;}}} void Printarr (int *arr, int length) {for (int i = 0;i < length;i++) {printf ("%d   ", Arr[i]);} printf ("\ n");} void Sortarr (int *arr, int length) {for (int i = 0;i < length-1;i++) {Findmax (arr + i, length-i);p Rintarr (arr + i, le ngth-i);}} int main () {int arr[10] = {0,2,87,49,34,62,53,6,44,90};int length = sizeof (arr)/sizeof (int); Sortarr (arr, length); Printarr (arr, length); System ("pause"); return 0;}

  

C Language Implementation Push sort

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.