Question
DEPTH FIRST SEARCH FOR THIS C++ PROBLEM Please help me write a function for this problem that uses Depth first search to group these pixels.
DEPTH FIRST SEARCH FOR THIS C++ PROBLEM
Please help me write a function for this problem that uses Depth first search to group these pixels. Each pixel is an object. below is the code for a stack class:
// array implementation of a stack
// derives from the ADT stack
#ifndef arrayStack_
#define arrayStack_
#include "stack.h"
#include "myExceptions.h"
#include "changeLength1D.h"
#include
template
class arrayStack : public stack
{
public:
arrayStack(int initialCapacity = 10);
~arrayStack() {delete [] stack;}
bool empty() const {return stackTop == -1;}
int size() const
{return stackTop + 1;}
T& top()
{
if (stackTop == -1)
throw stackEmpty();
return stack[stackTop];
}
void pop()
{
if (stackTop == -1)
throw stackEmpty();
stack[stackTop--].~T(); // destructor for T
}
void push(const T& theElement);
private:
int stackTop; // current top of stack
int arrayLength; // stack capacity
T *stack; // element array
};
template
arrayStack
{// Constructor.
if (initialCapacity
{ostringstream s;
s 0";
throw illegalParameterValue(s.str());
}
arrayLength = initialCapacity;
stack = new T[arrayLength];
stackTop = -1;
}
template
void arrayStack
{// Add theElement to stack.
if (stackTop == arrayLength - 1)
{// no space, double capacity
changeLength1D(stack, arrayLength, 2 * arrayLength);
arrayLength *= 2;
}
// add at stack top
stack[++stackTop] = theElement;
}
#endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started