DSA Assignment 3
DSA Assignment 3
DSA Assignment 3
Subject
Data Structures & Algorithms
Instructor:
Adnan Aslam
INPUT:
#include<iostream>
using namespace std;
if (largest != i) {
swap(arr[i], arr[largest]);
heapify(arr, N, largest);
}
}
if (smallest != i) {
swap(arr[i], arr[smallest]);
MinHeapify(arr, N, smallest);
}
}
int startIdx = (N / 2) - 1;
int startIdx = (N / 2) - 1;
arr[0] = lastElement;
N=N-1;
heapify(arr, N, 0);
}
int main()
{
int arr[] = {3,9,2,1,4,5};
int N = sizeof(arr)/sizeof(arr[0]);
cout<<"MinHeap: \n";
MinHeap(arr, N);
printHeap(arr,N);
cout<<"ExtractMax: "<<peekMin(arr,N)<<endl;
cout<<"Removing highest priority element from Heap: \n";
deleteNode(arr,N);
printHeap(arr,N);
cout<<"MaxHeap: \n";
// insertNode(arr,7,N);
MaxHeap(arr,N);
printHeap(arr, N);
cout<<"Removing highest priority element from Heap: \n";
deleteNode(arr, N);
printHeap(arr,N);
cout<<"ExtractMax: "<<peekMax(arr);
OUTPUT:
THANKYOU.