fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5. void heapsort(char *heap,int number);
  6.  
  7. int main()
  8. {
  9. char ch[11];
  10. int i;
  11. scanf("%s",ch);
  12. heapsort(ch,11);
  13. for(i=0;i<strlen(ch);i++)
  14. {
  15. printf("%c",ch[i]);
  16. }
  17.  
  18.  
  19.  
  20.  
  21. }
  22.  
  23.  
  24.  
  25.  
  26. void heapsort(char *heap,int number)
  27. {
  28. for(int i=1;i<number;i++)
  29. {
  30. int c=i;
  31. do{
  32. int root=(c-1)/2;
  33. if(heap[root]>heap[c])
  34. {
  35. int temp=heap[root];
  36. heap[root]=heap[c];
  37. heap[c]=temp;
  38. }
  39. c=root;
  40. }while(c!=0);
  41. }
  42.  
  43. for(int i=number-1;i>=0;i--)
  44. {
  45. int temp=heap[0];
  46. heap[0]=heap[i];
  47. heap[i]=temp;
  48.  
  49. int root=0;
  50. int c=1;
  51. do{
  52. c=2*root+1;
  53. if(heap[c]>heap[c+1]&&c<i-1)
  54. {
  55. c++;
  56. }
  57. if(heap[c]<heap[root]&&c<i)
  58. {
  59. int temp=heap[root];
  60. heap[root]=heap[c];
  61. heap[c]=temp;
  62. }
  63. root=c;
  64. }while(c<i);
  65. }
  66.  
  67. }
Success #stdin #stdout 0s 4460KB
stdin
100
stdout
yU100