ivolff

1

Oct 12th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  qwerty
  4. //
  5. //  Created by Святой Отец on 11.09.17.
  6. //  Copyright © 2017 Святой Отец. All rights reserved.
  7. //
  8.  
  9. #include <fstream>
  10. #include <iostream>
  11. #include <cmath>
  12.  
  13.  
  14. using namespace std;
  15.  
  16. bool IsHeap=true;
  17. int lenght=NULL;
  18.  
  19. void hueta(int* heap,int index){
  20.     if(IsHeap){
  21.     if(2*index+1<lenght)
  22.         if(heap[index]>=heap[2*index+1])
  23.                 IsHeap=false;
  24.             else
  25.                 hueta(heap,2*index+1);
  26.     else;
  27.     if(2*index+2<lenght)
  28.         if(heap[index]>=heap[2*index+2])
  29.             IsHeap=false;
  30.         else
  31.             hueta(heap,2*index+2);
  32.         else;
  33.     }
  34. }
  35.  
  36. int main(int argc, const char * argv[]) {
  37.     ifstream fin("/Users/i9788365/Desktop/qwerty/qwerty/1.rtf");
  38.     fin>>lenght;
  39.     int * heap = (int*) malloc(lenght + 1);
  40.     for(int i=0;i<lenght;i++)
  41.         cin>>heap[i];
  42.     int a;
  43.     fin>>a;
  44.     cout<<a<<lenght;
  45.     fin.close();
  46.     ofstream fout("isheap.out");
  47.     hueta(heap,0);
  48.     cout<<(IsHeap?"YES":"NO");
  49.     fout.close();
  50.     free(heap);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment