Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please complete the void remVertex(Vertex*& vHead, char label); . Be sure to use the function header as written. Remember, that you have to remove all

Please complete the void remVertex(Vertex*& vHead, char label);. Be sure to use the function header as written.

Remember, that you have to remove all the incoming and outgoing arcs in the data structure along with the vertex itself. Feel free to use the remArc function we wrote in the video to make your life easier. Think about what parameters it needs as input and how you might use it in the function.

For completeness's sake, also write the Vertex* findVertex(Vertex* vHead, char key); function. As mentioned in the video, the code itself has already been written and can be copied from other functions. For extra credit, replace that code in the other functions with this search function.

#IFNDEF VERTEX_H #DEFINE VERTEX_H

struct Vertex; struct Arc;

struct Vertex{ char data; Vertex* vNext; Arc*ahead;

};

struct Arc { Vertex* dest; Arc* aNext;

};

void addVertex(Verex* vhead, char label); void rmVertex(Vertex* vhead, char label); /// to remove Vertex vod addArc(Vertex *vHead, char from, char to); void rmArc(Vertex * vHead, char from, char to); Vertex* findVertex(Vertex* vHead, char key); void printGraph(Vertex* vHead);

#ENDIF

void rmArc(Vertex *vHead, char from, char to) { Vertex* fromVer = vhead; while(fromVer != nullptr && fromVer-> data < from) { fromVer = fromVer->vNext; } if(fromVer == nullptr || fromVer-> data > from) { cout << "Starting vertex is not in the list. "; return;

}

Arc* curArc = fromVer->aHead;

if (curArc == nullptr && curArc -> dest-> data > to) { cout << "There is no connection between these vertices "; return; } while(curArc->aNext != nullptr && curArc -> dest -> data < to) { curArc = curArc -> aNext; } if(curArc ->aNext == nullptr || curArc-> aNext-> dest-> data > to){ cout << "There is no connection: ";;

return; } else{ Arc* dltPtr = curArc -> aNext; curArc -> aNext = curArc -> aNext -> aNext; delete dltPtr; }

}

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions