Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

Discuss the need to redesign the office spaces.

Answered: 1 week ago