heapsort - My articles - Publisher - Information Technology
Saturday, 2016-12-03, 10:45 PM
ebooks Programming Computer Science
Welcome Guest | RSS
Site menu
Section categories
My articles [23]
Main » Articles » My articles

heapsort
#include<stdio.h>

void print();
void insert();
void shift_up(int);
int n;
int i=1,a[20];

void main()
  int num=0;
  printf("How many numbers you want to sort: ");
  scanf("%d",&n);
  insert();
  print();
  printf("plz give the position to shift_up: ");
  scanf("%d",&num);
  shift_up(num);
}
void insert()
{
 printf("Enter Numbers :");
  while(i<=n)
  {
    scanf("%d",&a[i]);
++i;
  }
}

void print()
{
  printf("Numbers are... ");
  for(i=1;i<=n;++i)
   printf("%d ",a[i]);
}

void shift_up(int n)
{
  int v=a[n];
  while((n>1)&&(a[n/2]<v))
  {
    a[n]=a[n/2];
n=n/2;
  }
  a[n]=v;
  print();
}
Category: My articles | Added by: Sumrat (2012-02-12)
Views: 260 | Rating: 0.0/0
Total comments: 0
Name *:
Email *:
Code *:
Our poll
Rate my site
Total of answers: 152
Statistics

Total online: 1
Guests: 1
Users: 0
Login form