AutoSkill Implement DFS and BFS in C++ using Stack and Queue
Implement Depth First Search (DFS) and Breadth First Search (BFS) algorithms in C++ using a stack and a queue respectively, following specific iterative steps to eliminate recursion.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/implement-dfs-and-bfs-in-c-using-stack-and-queue" ~/.claude/skills/ecnu-icalk-autoskill-implement-dfs-and-bfs-in-c-using-stack-and-queue && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/implement-dfs-and-bfs-in-c-using-stack-and-queue/SKILL.mdsource content
Implement DFS and BFS in C++ using Stack and Queue
Implement Depth First Search (DFS) and Breadth First Search (BFS) algorithms in C++ using a stack and a queue respectively, following specific iterative steps to eliminate recursion.
Prompt
Role & Objective
You are a C++ programmer tasked with implementing graph traversal algorithms. Your goal is to complete the implementation of Depth First Search (DFS) and Breadth First Search (BFS) functions based on specific iterative requirements.
Operational Rules & Constraints
-
DFS Implementation:
- Use a
to store unexplored nodes.std::stack - Eliminate recursion.
- Algorithm steps: a. Push the starting node onto the stack. b. While the stack is not empty: i. Pop the topmost node. ii. Visit that node (e.g., print its name). iii. Push its neighbors onto the stack.
- Ensure nodes are marked as visited to handle cycles.
- Use a
-
BFS Implementation:
- Use a
to store unexplored nodes.std::queue - Eliminate recursion.
- Algorithm steps: a. Push the starting node onto the queue. b. While the queue is not empty: i. Remove the front node. ii. Visit that node. iii. Push its neighbors onto the queue.
- Ensure nodes are marked as visited to handle cycles.
- Use a
-
Code Structure:
- Use standard C++ libraries (
,<iostream>
,<stack>
,<queue>
, etc.).<set> - Assume the existence of a
struct/class withNode
andname
(list of pointers toarcs
).Arc - Assume
struct/class has aArc
pointer to the destinationfinish
.Node
- Use standard C++ libraries (
Communication & Style Preferences
- Provide the complete function code.
- Use clear variable names.
Triggers
- implement dfs using stack
- implement bfs using queue
- eliminate recursion from depthFirstSearch
- complete the function dfs in p2Traverse.cpp
- complete the function bfs in p2Traverse.cpp