#include<stdio.h>
#include<iostream>
using namespace std;
int arr[16] = {0,};
int stack[100];
int top = -1;
int q[100];
int pre = 0, tail = 0;
void _dfs() {
int stIdx = 0;
int currIdx = 0;
// init push
stack[++top] = currIdx; // push
while(1) {
if(top==-1)
break;
currIdx = stack[top--]; //pop
cout<<currIdx<<endl;
if(currIdx*2+2 <= 16)
stack[++top] = currIdx*2+2; // push child 1
else {
}
if(currIdx*2+1 <= 16)
stack[++top] = currIdx*2+1; // push child 2
else {
}
}
}
void _bfs() {
int stIdx = 0;
int currIdx = 0;
// init push
q[tail++] = currIdx; // push
while(1) {
if(pre==tail)
break;
currIdx = q[pre++]; //pop
cout<<currIdx<<endl;
if(currIdx*2+1 <= 16) {
q[tail++] = currIdx*2+1; // push child 1
}
else {
}
if(currIdx*2+2 <= 16)
q[tail++] = currIdx*2+2; // push child 2
else {
}
}
}
int main() {
//init
for(int i=0;i<16;i++) {
arr[i] = i;
}
//_dfs();
_bfs();
return 0;
}
'소프트웨어 > Algorithm' 카테고리의 다른 글
week3] dijkstra(heap sort, priority queue) (0) | 2015.09.20 |
---|---|
week2] sort, tree, heap, graph 자료구조 마무리 (0) | 2015.09.20 |
Heap Sort (0) | 2015.09.14 |
week1] Stack Queue (1) | 2015.08.27 |
baejoon] 2178 미로탐색 (0) | 2015.04.28 |
Algo] long long형 변수의 사용은 %lld로!!! (0) | 2014.04.20 |
Baekjoon] 소트인사이드 (퀵정렬) (0) | 2014.04.20 |