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

 DEPTH FIRST SEARCH FOR THIS C++ PROBLEM Please help me writea function for this problem that uses Depth first search to group

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::arrayStack(int initialCapacity)

{// Constructor.

if (initialCapacity

{ostringstream s;

s 0";

throw illegalParameterValue(s.str());

}

arrayLength = initialCapacity;

stack = new T[arrayLength];

stackTop = -1;

}

template

void arrayStack::push(const T& theElement)

{// 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!