From 9d3873196c0c4d16e51ab9c66a9ec0626f5f9b9f Mon Sep 17 00:00:00 2001 From: Vatsal2010 <100271947+Vatsal2010@users.noreply.github.com> Date: Wed, 19 Oct 2022 12:24:41 +0530 Subject: [PATCH] Add files via upload --- lab5q1.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 lab5q1.cpp diff --git a/lab5q1.cpp b/lab5q1.cpp new file mode 100644 index 0000000..513d799 --- /dev/null +++ b/lab5q1.cpp @@ -0,0 +1,60 @@ +#include +using namespace std; +void Max_heapify(int arr2[],int f,int size){ + int max=f,l=f*2,r=f*2+1,t; + if(l<=size && arr2[l]>arr2[max]) {max=l;} + if(r<=size && arr2[r]>arr2[max]) {max=r;} + if(f!=max){ + t=arr2[f]; + arr2[f]=arr2[max]; + arr2[max]=t; + Max_heapify(arr2,max,size); + } +} +void Max_heap (int arr1[],int start,int end){ + for(int i=(end)/2;i>=start;i--){ + Max_heapify(arr1,i,end); + } +} + +void level_ordered(int arr[] ,int size){ + int g=true; + int i=2,k,m=1,ct=0; + cout<<"Level order traversal of array is : "< "<size) g=false; + i=i+pow(2,ct); + + } +} +void heapsort(int arr[],int k){ + int i,t; + for(int i=k;i>=2;i--){ + t=arr[1]; + arr[1]=arr[i]; + arr[i]=t; + Max_heapify(arr,1,i-1); + } +} +int main(){ + int n; + cin>>n; + int arr[n+1]; + for(int i=1;i>arr[i];} + Max_heap(arr,1,n); + heapsort(arr,n); + cout<<"Sorted Array using heapsort is : "<