For reference:
class stack {
public:
stack();
~stack();
bool isFull();
bool isEmpty();
void push(char);
void pop();
char peek();
int count;
private:
char * arr;
int top;
};
class queue {
public:
queue();
~queue();
bool isFull();
bool isEmpty();
void enQ(char);
char deQ();
char slash();
char back();
char peek();
int count;
private:
char * arr;
int front;
int rear;
};
// List of all function logic that you need:
void parseItem(stack * map[], int col_selected, int cols, queue * bag, queue * loot, char item);
void bombEffect(stack * map[], int col_selected, int cols);
void pigEffect(queue * loot);
void cloverEffect(stack * map[], int col_selected, int cols, queue * loot);
void flashEffect(stack * map[], int cols);
void magnetEffect(stack * map[], int cols, queue * loot, queue * bag);
//This one you should build to debug
void printBag(queue * Bag);
void printLoot(queue * Loot);
void printFinal(stack * map[], int cols);
void printBag(queue * Bag) {
cout << "FINAL BAG:\n";
int unload = Bag->count;
for(int i = 0; i < unload; i++) {
if(!Bag->isEmpty()) {
cout << Bag->deQ();
if(i!= (unload - 1)) cout << " ";
}
}
cout << endl;
}
void printLoot(queue * Loot) {
cout << "FINAL BAG:\n";
int unload = Loot->count;
for(int i = 0; i < unload; i++) {
if(!Loot->isEmpty()) {
cout << Loot->deQ();
cout << " ";
}
}
cout << endl;
}
/*========= STACK IMPLEMENTATION =========*/
stack::stack() {
arr = new char[MAX_SIZE];
top = -1;
count = 0;
//---Stack Debugger
// stack holder;
// holder.push('a');
// holder.push('b');
// holder.pop();
// holder.push('c');
// cout << "Top: " << holder.peek() << endl;
// cout << "Count: " << holder.count << endl;
// holder.pop();
// holder.pop();
// holder.peek();
}
stack::~stack() {
delete arr;
arr = nullptr;
}
bool stack::isFull() {
return(top == (MAX_SIZE - 1));
}
bool stack::isEmpty() {
return(top == -1);
}
void stack::push(char item) {
if(!isFull()) {
arr[++top] = item;
// cout << "[LOG] " << "Pushed new item: " << arr[top] << endl;
count++;
} else {
//cout << "[LOG] " << "Stack is full" << endl;
}
}
void stack::pop() {
if(!isEmpty()) {
char topElement = arr[top--];
// cout << "[LOG] " << "Poped item: " << topElement << endl;
count--;
} else {
//cout << "[LOG] " << "pop Stack is empty" << endl;
}
}
char stack::peek() {
if(!isEmpty()) {
char topElement = arr[top];
// cout << "[LOG] " << "Top Item is " << topElement << endl;
return topElement;
} else {
//cout << "[LOG] " << "peek Stack is empty" << endl;
return '$';
}
}
/*========= QUEUE IMPLEMENTATION =========*/
queue::queue() {
arr = new char[MAX_SIZE];
front = -1;
rear = -1;
count = 0;
//---Queue Debugger
// queue line;
// line.enQ('a');
// line.enQ('b');
// cout << "Count: " << line.count << endl;
// char take = line.deQ();
// cout << "Grabbed: " << take << endl;
// cout << "Count: " << line.count << endl;
// line.peek();
// take = line.deQ();
// take = line.deQ();
}
queue::~queue() {
delete arr;
arr = nullptr;
}
bool queue::isFull() {
return(front == 0 && rear == (MAX_SIZE - 1));
}
bool queue::isEmpty() {
return(count == 0);
}
void queue::enQ(char item) {
if(!isFull()) {
if(front == -1) front++;
arr[++rear] = item;
// cout << "[LOG] " << "Appended new item: " << arr[rear] << endl;
count++;
} else {
//cout << "[LOG] " << "Queue is full" << endl;
}
}
char queue::deQ() {
if(!isEmpty()) {
char frontElement = arr[front++];
// cout << "[LOG] " << "Grab Queue: " << frontElement << endl;
count--;
return frontElement;
} else {
//cout << "[LOG] " << "Queue is empty" << endl;
return '$';
}
}
char queue::slash() {
if(!isEmpty()) {
char rearElement = arr[rear--];
count--;
// cout << "[LOG] " << "Sneak Peek: " << frontElement << endl;
return rearElement;
} else {
//cout << "[LOG] " << "Queue is empty" << endl;
return '$';
}
}
char queue::back() {
if(!isEmpty()) {
char rearElement = arr[rear];
// cout << "[LOG] " << "Sneak Peek: " << frontElement << endl;
return rearElement;
} else {
//cout << "[LOG] " << "Queue is empty" << endl;
return '$';
}
}
char queue::peek() {
if(!isEmpty()) {
char frontElement = arr[front];
// cout << "[LOG] " << "Sneak Peek: " << frontElement << endl;
return frontElement;
} else {
//cout << "[LOG] " << "Queue is empty" << endl;
return '$';
}
}
In this notespace, I will share my original journey of thinkering with IoT. The mission is to create a monitoring system to gather data from a drying device and save it into a datasheet.
Mar 29, 2025Programmer
Mar 17, 2025Strategy is a plan of change to achieve an objective
Sep 15, 2024Basic control requirements:
Jul 31, 2024or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up