Repository navigation
Expand file tree
/
Copy pathDataStructures.h
More file actions
91 lines (74 loc) · 1.59 KB
/
Copy pathDataStructures.h
File metadata and controls
91 lines (74 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
#include <iostream>
#include "Process.h"
using namespace std;
class Node {
public:
Process data;
Node* next;
Node(Process p) : data(p), next(nullptr) {
if (data.id < 0) {
throw invalid_argument("invalid id");
}
}
};
class ProcessQueue {
private:
Node* front;
Node* rear;
public:
ProcessQueue();
~ProcessQueue();
void enqueue(Process value);
Process dequeue();
Process getFront();
Process getRear();
bool isEmpty();
void print();
};
class ProcessList {
private:
Node* head;
int count;
public:
ProcessList() ;
void addProcess(Process p); // Sorted insert
void push_back(Process p); // Append to end
void clear();
Node* getHead();
int getSize();
};
class DynamicArray{
private:
Process* data;
int size;
int capacity;
void resize();
public:
DynamicArray(int cap = 4);
DynamicArray(const DynamicArray& other);
~DynamicArray();
void push_back(const Process& value);
Process &operator[](int index);
int getSize();
void removeLast();
};
class PriorityQueue {
private:
DynamicArray heap;
bool isMinHeap;
int parent(int i) {return (i-1)/2;};
int leftChild(int i) {return 2*i+1;};
int rightChild(int i) {return 2*i+2;};
void heapifyUp(int index);
void heapifyDown(int index);
bool hasHigherPriority(Process p1, Process p2);
void swap(int p1, int p2);
public:
PriorityQueue(bool minMode);
void enqueue(Process p);
Process dequeue();
Process peek();
bool isEmpty();
int getSize();
};