depth-first search you can see how this code embodies the three rules listed earlier it loops until the stack is empty within the loopit does four things it examines the vertex at the top of the stackusing peek( it tries to find an unvisited neighbor of this vertex if it doesn' find oneit pops the stack if it finds such vertexit visits it and pushes it onto the stack here' the code for the dfs(methodpublic void dfs(/depth-first search /begin at vertex vertexlist[ wasvisited true/mark it displayvertex( )/display it thestack push( )/push it while!thestack isempty(/until stack empty/get an unvisited vertex adjacent to stack top int getadjunvisitedvertexthestack peek()if( =- /if no such vertexthestack pop()/pop new one else /if it existsvertexlist[vwasvisited true/mark it displayvertex( )/display it thestack push( )/push it /end while /stack is emptyso we're done for(int = <nvertsj++/reset flags vertexlist[jwasvisited false/end dfs at the end of dfs()we reset all the wasvisited flags so we'll be ready to run dfs(again later the stack should already be emptyso it doesn' need to be reset now we have all the pieces of the graph class we need here' some code that creates graph objectadds some vertices and edges to itand then performs depth-first searchgraph thegraph new graph()thegraph addvertex(' ')/ thegraph addvertex(' ')/ thegraph addvertex(' ')/ thegraph addvertex(' ')/ thegraph addvertex(' ')/ (start for dfs