Vous êtes sur la page 1sur 6

#include <iostream>

#include <cstdlib>

void heapifyup1(int index);


public:

#include <vector>

vector<int> heap;

#include <iterator>

void Insert(int element);

using namespace std;

void Insert1(int element);


int ExtractMin();

class Disk

int ExtractMax();

void DisplayHeap();

private:

int Size();

vector<int> filet;

void DeleteMin();

public:
void insert(int file);

void DeleteMax();
};

void displaydisk();
int size();
};

class Heap
{
private:

int left(int parent);


int right(int parent);
int parent(int child);
void heapifydown(int index);
void heapifydown1(int index);

#include <iostream>

void heapifyup(int index);

#include <cstdlib>

#include <vector>

while (pos != filet.end())

#include <iterator>

#include"Disk.h"

cout<<*pos<<" ";
pos++;

void Disk::insert(int file)

cout<<endl;
filet.push_back(file);

int Disk::size()

int Heap::Size()

{
int madhesia=0;

vector<int>::iterator
pos=filet.begin();
while(pos!=filet.end())
{

return heap.size();
}

void Heap::Insert(int element)


{

madhesia=madhesia+*pos;

heap.push_back(element);

pos++;
}

heapifyup(heap.size() -1);
}

return madhesia;
}

void Heap::Insert1(int element)


{

void Disk::displaydisk()

heap.push_back(element);

heapifyup1(heap.size()-1);

vector <int>::iterator pos =


filet.begin();
cout<<"Filet ne disk jane --> ";

void Heap::DeleteMin()
{
if (heap.size() == 0)

cout<<"Element
Deleted"<<endl;
}

{
cout<<"Heap is
Empty"<<endl;

int Heap::ExtractMin()
{

return;

if (heap.size() == 0)

heap[0] = heap.at(heap.size() 1);

return -1;
}

heap.pop_back();

else

heapifydown(0);
cout<<"Element
Deleted"<<endl;

return heap.front();
}

}
int Heap::ExtractMax()
void Heap::DeleteMax()

{
if (heap.size() == 0)

if (heap.size() == 0)

return -1;

{
}

cout<<"Heap is
Empty"<<endl;

else

return;
}

return heap.front();
}

heap[0] = heap.at(heap.size() 1);


heap.pop_back();
heapifydown1(0);

void Heap::DisplayHeap()
{

vector <int>::iterator pos =


heap.begin();
cout<<"Heap --> ";

else
return -1;
}

while (pos != heap.end())


{
cout<<*pos<<" ";
pos++;

int Heap::parent(int child)


{

int p = (child - 1)/2;

cout<<endl;

if (child == 0)

return -1;
else
return p;

int Heap::left(int parent)

{
int l = 2 * parent + 1;
if (l < heap.size())
return l;
else
return -1;

void Heap::heapifyup(int in)


{
if (in >= 0 && parent(in) >= 0
&& heap[parent(in)] > heap[in])

{
int temp = heap[in];
heap[in] = heap[parent(in)];

int Heap::right(int parent)

heap[parent(in)] = temp;

heapifyup(parent(in));
int r = 2 * parent + 2;
if (r < heap.size())
return r;

}
}

void Heap::heapifyup1(int in)


//MAX Heap

heap[child] = temp;
heapifydown(child);

if (in >= 0 && parent(in) >= 0


&& heap[parent(in)] < heap[in])

{
int temp = heap[in];

void Heap::heapifydown1(int in)

heap[in] = heap[parent(in)];

heap[parent(in)] = temp;
heapifyup1(parent(in));

int child = left(in);


int child1 = right(in);

if (child >= 0 && child1 >= 0


&& heap[child] < heap[child1])

{
void Heap::heapifydown(int in)
{

child = child1;
}
if (child1> 0)

int child = left(in);


int child1 = right(in);
if (child >= 0 && child1 >= 0
&& heap[child] > heap[child1])

{
int temp = heap[in];
heap[in] = heap[child];
heap[child] = temp;

{
child = child1;

heapifydown1(child);
}}

}
if (child > 0)
{
int temp = heap[in];
heap[in] = heap[child];

Vous aimerez peut-être aussi