Skip to content

Commit ed232e2

Browse files
committed
예제 구조 변경 및 리팩토링
1 parent fa70c4c commit ed232e2

14 files changed

Lines changed: 307 additions & 15 deletions

File tree

src/components/ide/IDE.jsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Editor from '@monaco-editor/react';
55
import VisualizationModal from './VisualizationModal';
66
import './IDE.css';
77
import config from '../../config';
8-
import { jsonExamples } from './mockData';
8+
import { codeExamples as codeExampleMocks, jsonExamples as jsonExampleMocks } from './mockData';
99

1010
// 🎨 Feather Icons CDN 로드 (원본 유지)
1111
if (!document.querySelector('script[src*="feather"]')) {
@@ -22,16 +22,8 @@ if (!document.querySelector('script[src*="feather"]')) {
2222
// ⛔ Script error 방지를 위해 applyResizeObserverFix 함수 정의 전체를 제거했습니다.
2323

2424
const IDE = () => {
25-
// 🆕 더미 파일 데이터 (내용 축약)
26-
const [dummyFiles] = useState([
27-
{ name: "bubble_sort.c", type: "code", code: `#include <stdio.h>\n\nvoid bubbleSort(int arr[], int n) { /* ... */ }` },
28-
{ name: "linked_list.c", type: "code", code: `#include <stdio.h>\n#include <stdlib.h>\n\nstruct Node { /* ... */ }` },
29-
{ name: "fibonacci.c", type: "code", code: `#include <stdio.h>\n\nint fibonacci(int n) { /* ... */ }` },
30-
{ name: "binary_tree.c", type: "code", code: `#include <stdio.h>\n#include <stdlib.h>\n\nstruct Node { /* ... */ }` },
31-
{ name: "heap.c", type: "code", code: `#include <stdio.h>\n\nvoid heapify(int arr[], int n, int i) { /* ... */ }` },
32-
{ name: "graph.c", type: "code", code: `#include <stdio.h>\n#include <stdlib.h>\n\n#define MAX_VERTICES 100\n\nstruct Graph { /* ... */ }` },
33-
...jsonExamples
34-
]);
25+
// 🆕 더미 파일 데이터 (mockData 기반)
26+
const [dummyFiles] = useState(() => [...codeExampleMocks, ...jsonExampleMocks]);
3527

3628
// 🆕 사이드바 섹션 상태 관리 (원본 유지)
3729
const [sidebarSections, setSidebarSections] = useState({
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const binaryTreeExample = `#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
struct Node {
5+
int data;
6+
struct Node* left;
7+
struct Node* right;
8+
};
9+
10+
struct Node* createNode(int data) {
11+
struct Node* node = (struct Node*)malloc(sizeof(struct Node));
12+
node->data = data;
13+
node->left = NULL;
14+
node->right = NULL;
15+
return node;
16+
}
17+
18+
void inorderTraversal(struct Node* root) {
19+
if (root != NULL) {
20+
inorderTraversal(root->left);
21+
printf("%d ", root->data);
22+
inorderTraversal(root->right);
23+
}
24+
}
25+
26+
int main() {
27+
struct Node* root = createNode(1);
28+
root->left = createNode(2);
29+
root->right = createNode(3);
30+
root->left->left = createNode(4);
31+
root->left->right = createNode(5);
32+
33+
printf("중위 순회: ");
34+
inorderTraversal(root);
35+
printf("\\n");
36+
37+
return 0;
38+
}`;
39+
40+
export default binaryTreeExample;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const bubbleSortExample = `#include <stdio.h>
2+
3+
void bubbleSort(int arr[], int n) {
4+
int i, j;
5+
for (i = 0; i < n - 1; i++) {
6+
for (j = 0; j < n - i - 1; j++) {
7+
if (arr[j] > arr[j + 1]) {
8+
int temp = arr[j];
9+
arr[j] = arr[j + 1];
10+
arr[j + 1] = temp;
11+
}
12+
}
13+
}
14+
}
15+
16+
int main() {
17+
int arr[] = {64, 34, 25, 12, 22, 11, 90};
18+
int n = sizeof(arr) / sizeof(arr[0]);
19+
20+
bubbleSort(arr, n);
21+
22+
printf("정렬된 배열: ");
23+
for (int i = 0; i < n; i++) {
24+
printf("%d ", arr[i]);
25+
}
26+
printf("\\n");
27+
28+
return 0;
29+
}`;
30+
31+
export default bubbleSortExample;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const fibonacciExample = `#include <stdio.h>
2+
3+
int fibonacci(int n) {
4+
if (n <= 1)
5+
return n;
6+
return fibonacci(n - 1) + fibonacci(n - 2);
7+
}
8+
9+
int main() {
10+
int n = 10;
11+
printf("피보나치 수열 (n=%d): ", n);
12+
for (int i = 0; i < n; i++) {
13+
printf("%d ", fibonacci(i));
14+
}
15+
printf("\\n");
16+
return 0;
17+
}`;
18+
19+
export default fibonacciExample;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const graphExample = `#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
#define MAX_VERTICES 100
5+
6+
struct Graph {
7+
int vertices;
8+
int adjMatrix[MAX_VERTICES][MAX_VERTICES];
9+
};
10+
11+
void initGraph(struct Graph* graph, int vertices) {
12+
graph->vertices = vertices;
13+
for (int i = 0; i < vertices; i++) {
14+
for (int j = 0; j < vertices; j++) {
15+
graph->adjMatrix[i][j] = 0;
16+
}
17+
}
18+
}
19+
20+
void addEdge(struct Graph* graph, int src, int dest) {
21+
graph->adjMatrix[src][dest] = 1;
22+
graph->adjMatrix[dest][src] = 1;
23+
}
24+
25+
void printGraph(struct Graph* graph) {
26+
printf("인접 행렬:\\n");
27+
for (int i = 0; i < graph->vertices; i++) {
28+
for (int j = 0; j < graph->vertices; j++) {
29+
printf("%d ", graph->adjMatrix[i][j]);
30+
}
31+
printf("\\n");
32+
}
33+
}
34+
35+
int main() {
36+
struct Graph graph;
37+
initGraph(&graph, 5);
38+
39+
addEdge(&graph, 0, 1);
40+
addEdge(&graph, 0, 4);
41+
addEdge(&graph, 1, 2);
42+
addEdge(&graph, 1, 3);
43+
addEdge(&graph, 1, 4);
44+
addEdge(&graph, 2, 3);
45+
addEdge(&graph, 3, 4);
46+
47+
printGraph(&graph);
48+
49+
return 0;
50+
}`;
51+
52+
export default graphExample;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const heapExample = `#include <stdio.h>
2+
3+
void heapify(int arr[], int n, int i) {
4+
int largest = i;
5+
int left = 2 * i + 1;
6+
int right = 2 * i + 2;
7+
8+
if (left < n && arr[left] > arr[largest])
9+
largest = left;
10+
11+
if (right < n && arr[right] > arr[largest])
12+
largest = right;
13+
14+
if (largest != i) {
15+
int temp = arr[i];
16+
arr[i] = arr[largest];
17+
arr[largest] = temp;
18+
heapify(arr, n, largest);
19+
}
20+
}
21+
22+
void heapSort(int arr[], int n) {
23+
for (int i = n / 2 - 1; i >= 0; i--)
24+
heapify(arr, n, i);
25+
26+
for (int i = n - 1; i >= 0; i--) {
27+
int temp = arr[0];
28+
arr[0] = arr[i];
29+
arr[i] = temp;
30+
heapify(arr, i, 0);
31+
}
32+
}
33+
34+
int main() {
35+
int arr[] = {12, 11, 13, 5, 6, 7};
36+
int n = sizeof(arr) / sizeof(arr[0]);
37+
38+
heapSort(arr, n);
39+
40+
printf("정렬된 배열: ");
41+
for (int i = 0; i < n; i++)
42+
printf("%d ", arr[i]);
43+
printf("\\n");
44+
45+
return 0;
46+
}`;
47+
48+
export default heapExample;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const linkedListExample = `#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
struct Node {
5+
int data;
6+
struct Node* next;
7+
};
8+
9+
void printList(struct Node* node) {
10+
while (node != NULL) {
11+
printf("%d -> ", node->data);
12+
node = node->next;
13+
}
14+
printf("NULL\\n");
15+
}
16+
17+
int main() {
18+
struct Node* head = NULL;
19+
struct Node* second = NULL;
20+
struct Node* third = NULL;
21+
22+
head = (struct Node*)malloc(sizeof(struct Node));
23+
second = (struct Node*)malloc(sizeof(struct Node));
24+
third = (struct Node*)malloc(sizeof(struct Node));
25+
26+
head->data = 1;
27+
head->next = second;
28+
29+
second->data = 2;
30+
second->next = third;
31+
32+
third->data = 3;
33+
third->next = NULL;
34+
35+
printList(head);
36+
37+
return 0;
38+
}`;
39+
40+
export default linkedListExample;

src/components/ide/mockData/index.js

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,98 @@
66
* 🗂️ JSON 기반 Mock 데이터 매니저
77
*/
88

9+
// 코드 예제 문자열 import
10+
import bubbleSortCode from './codeExamples/bubbleSort';
11+
import linkedListCode from './codeExamples/linkedList';
12+
import fibonacciCode from './codeExamples/fibonacci';
13+
import binaryTreeCode from './codeExamples/binaryTree';
14+
import heapCode from './codeExamples/heap';
15+
import graphCode from './codeExamples/graph';
16+
917
// JSON 파일들 직접 import (DV-Flow v1.3 스키마)
10-
import bubbleSortJson from './bubbleSort.json';
11-
import graphJson from './graph.json';
18+
import binaryTreeJson from './jsonExamples/binaryTree.json';
19+
import bubbleSortJson from './jsonExamples/bubbleSort.json';
20+
import fibonacciJson from './jsonExamples/fibonacci.json';
21+
import graphJson from './jsonExamples/graph.json';
22+
import heapJson from './jsonExamples/heap.json';
23+
import linkedListJson from './jsonExamples/linkedList.json';
24+
25+
// 코드 예제 파일들을 객체 형태로 export
26+
export const codeExamples = [
27+
{
28+
name: 'bubble_sort.c',
29+
type: 'code',
30+
code: bubbleSortCode
31+
},
32+
{
33+
name: 'linked_list.c',
34+
type: 'code',
35+
code: linkedListCode
36+
},
37+
{
38+
name: 'fibonacci.c',
39+
type: 'code',
40+
code: fibonacciCode
41+
},
42+
{
43+
name: 'binary_tree.c',
44+
type: 'code',
45+
code: binaryTreeCode
46+
},
47+
{
48+
name: 'heap.c',
49+
type: 'code',
50+
code: heapCode
51+
},
52+
{
53+
name: 'graph.c',
54+
type: 'code',
55+
code: graphCode
56+
}
57+
];
1258

1359
// JSON 예제 파일들을 객체 형태로 export
1460
export const jsonExamples = [
61+
{
62+
name: 'binaryTree.json',
63+
type: 'json',
64+
code: JSON.stringify(binaryTreeJson, null, 2)
65+
},
1566
{
1667
name: 'bubbleSort.json',
1768
type: 'json',
1869
code: JSON.stringify(bubbleSortJson, null, 2)
1970
},
71+
{
72+
name: 'fibonacci.json',
73+
type: 'json',
74+
code: JSON.stringify(fibonacciJson, null, 2)
75+
},
2076
{
2177
name: 'graph.json',
2278
type: 'json',
2379
code: JSON.stringify(graphJson, null, 2)
80+
},
81+
{
82+
name: 'heap.json',
83+
type: 'json',
84+
code: JSON.stringify(heapJson, null, 2)
85+
},
86+
{
87+
name: 'linkedList.json',
88+
type: 'json',
89+
code: JSON.stringify(linkedListJson, null, 2)
2490
}
2591
];
2692

2793
// JSON 데이터 객체 매핑 (파일명 -> 원본 JSON 데이터)
2894
const jsonDataMap = {
95+
binaryTree: binaryTreeJson,
2996
bubbleSort: bubbleSortJson,
30-
graph: graphJson
97+
fibonacci: fibonacciJson,
98+
graph: graphJson,
99+
heap: heapJson,
100+
linkedList: linkedListJson
31101
};
32102

33103
// JSON 파일들을 동적으로 import하는 함수 (호환성 유지)
@@ -48,7 +118,7 @@ const importJsonFile = async (filename) => {
48118

49119
export class JsonVisualizationManager {
50120
// 📋 현재 사용 가능한 JSON 파일들 (확장자 제외)
51-
static availableJsonFiles = ['bubbleSort', 'graph'];
121+
static availableJsonFiles = ['binaryTree', 'bubbleSort', 'fibonacci', 'graph', 'heap', 'linkedList'];
52122

53123
// 🗄️ 로드된 JSON 데이터 캐시
54124
static jsonCache = new Map();
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)