Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[daadaadaah] Graph 구현 #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

daadaadaah
Copy link
Collaborator

No description provided.

Copy link
Member

@Woomin-Jeon Woomin-Jeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 케이스도 엄청 꼼꼼히 짜셨네요! 정말 고민의 흔적이 많이 보이는 코드였습니다. 잘봤습니다!

constructor(value) {
this.value = value;
this.marked = false;
this.adjustNodes = new Set();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adjust는 동사라서 adjustedNodes 처럼 명사 변수를 사용하시는 건 어떨까요?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 혹시 오타 아닐까요?
인접 노드 adjacent node 인 것 같아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오타예요!!ㅎㅎ adjacentNodes로 수정해야할 것 같아요~ 👍

Comment on lines +158 to +179
dfs(startingVertex) {
let stack = new Stack();
let circuitousPath = [];

stack.push(startingVertex);
this.vertexs.get(startingVertex).marked = true;

while (stack.count > 0) {
const currentNode = stack.pop().data;
circuitousPath.push(currentNode);

const adjacencyListOfCurrentNode = this.vertexs.get(currentNode).adjustNodes;
for (let node of adjacencyListOfCurrentNode) {
if (!this.vertexs.get(node).marked) {
stack.push(node);
this.vertexs.get(node).marked = true;
}
}
}

return circuitousPath;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DFS를 재귀를 안쓰고 별도로 스택을 만들어서 구현한 코드는 처음보네요! 요렇게도 할 수 있구나 하면서 배우고갑니다!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 저도 스택으로 구현 한건 처음 봤습니다! 저도 배워 갑니다!

Copy link
Collaborator

@gyim1345 gyim1345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dfs와 bfs까지 구현하셨군요! 고생하셨습니다!

constructor(value) {
this.value = value;
this.marked = false;
this.adjustNodes = new Set();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 혹시 오타 아닐까요?
인접 노드 adjacent node 인 것 같아요!

Comment on lines +158 to +179
dfs(startingVertex) {
let stack = new Stack();
let circuitousPath = [];

stack.push(startingVertex);
this.vertexs.get(startingVertex).marked = true;

while (stack.count > 0) {
const currentNode = stack.pop().data;
circuitousPath.push(currentNode);

const adjacencyListOfCurrentNode = this.vertexs.get(currentNode).adjustNodes;
for (let node of adjacencyListOfCurrentNode) {
if (!this.vertexs.get(node).marked) {
stack.push(node);
this.vertexs.get(node).marked = true;
}
}
}

return circuitousPath;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 저도 스택으로 구현 한건 처음 봤습니다! 저도 배워 갑니다!


graph.removeArc('A', 'C');

expect(graph.getGraph().get('A').adjustNodes.has('C')).toBeFalsy();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 조금 많이 길어 지는 것 같은데 메서드를 하나 만드는건 어떨까요?
Graph{
....
vertexHasAdjacentVertex(vertex) {
return function(targetVertex){
return this.vertexs.get(vertex).adjacentNode.has(targetVertex)
}
}
...
}
...
test{
...
expect(graph.vertexHasAdjacentVertex('A')('C').toBeFalsy();
...
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오~ 메서드로 하나 만드는게 더 좋겠네용!!ㅎㅎㅎ 좋은 지적 감사합니다~ 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants