Skip to content

[20240812] 임창희_10회차 자료구조 #34

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 26 additions & 52 deletions changhee/src/main/java/com/dataStructure/Main.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,34 @@
package com.dataStructure;

import com.dataStructure.collections.arrayDeque.MyArrayDeque;
import com.dataStructure.collections.arrayList.ArrayList;
import com.dataStructure.collections.arrayList.MyList;
import com.dataStructure.collections.arrayStack.MyArrayStack;
import com.dataStructure.collections.circularSinglyLinkedList.CircularSinglyLinkedList;
import com.dataStructure.collections.linkedList.MyDoublyLinkedList;
import com.dataStructure.collections.linkedList.MySingleLinkedList;
import com.dataStructure.collections.linkedQueue.MyLinkedQueue;
import com.dataStructure.collections.linkedStack.MyLinkedStack;

import com.dataStructure.collections.binaryTree.MyBinaryTree;

public class Main {
public static void main(String[] args) {
MyLinkedStack<Long> list = new MyLinkedStack<>();
System.out.println("빈 리스트가 출력되어야 한다");
System.out.println("list = " + list);
System.out.println();

System.out.println("list는 1, 2, 3, 4를 포함해야 한다");
list.push(1L);
list.push(2L);
list.push(3L);
list.push(4L);
System.out.println("list = " + list);
System.out.println();

System.out.println("값 4가 삭제되어야 한다");
System.out.println("삭제 된 값 : "+list.pop());
System.out.println("list = " + list);
System.out.println();

System.out.println("list의 크기는 3이어야 한다");
System.out.println("list.size() = " + list.size());
System.out.println();

System.out.println("list 마지막 값인 3이 나와야한다.");
System.out.println("list.peek() = " + list.peek());
System.out.println();

System.out.println("list 첫 번째 값인 1이 나와야한다.");
System.out.println("list.search = " + list.search(1L));
System.out.println("list = " + list);
System.out.println();

System.out.println("list에 4가 없으므로 -1이 나와야 한다.");
System.out.println("list.search = " + list.search(4));
System.out.println();


System.out.println("clear를 하면 list는 비어있어야 한다");
list.clear();
System.out.println("list = " + list);
System.out.println();

System.out.println("clear를 하면 list는 비어있어야 한다");
System.out.println("list.empty() =" + list.isEmpty());
MyBinaryTree<Integer> tree = new MyBinaryTree<>();
// 예제에 있는 트리와 동일하게 구성
tree.add(23);
tree.add(12);
tree.add(40);
tree.add(7);
tree.add(16);
tree.add(1);
tree.add(14);
tree.add(17);
tree.add(29);
tree.add(55);
tree.add(61);

System.out.print("전위 순회 : ");
tree.preorder(); // 전위 순회
System.out.println();

System.out.print("중위 순회 : ");
tree.inorder(); // 중위 순회
System.out.println();

System.out.print("후위 순회 : ");
tree.postorder(); // 후위 순회
System.out.println();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.dataStructure.collections.binarySearchTree;

public interface CustomBinarySearchTree<E> {
boolean add(E value);

E remove(Object o) ;

int size() ;

boolean isEmpty();

boolean contains(Object o);

void clear();

void preorder();

void inorder();

void postorder();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.dataStructure.collections.binarySearchTree;


public class MyBinarySearchTree implements CustomBinarySearchTree{

private Node root;
private int size;
public MyBinarySearchTree(){
this.root = null;
size = 0;
}


public class Node{
private Object value;
private Node leftChild;
private Node rightChild;

public Node(Object value){
this.value = value;
this.leftChild = null;
this.rightChild = null;
}
}

@Override
public boolean add(Object value) {

if(root == null){
Node newNode = new Node(value);
root = newNode;
size++;
}
Node current = root;
return false;
}

@Override
public Object remove(Object o) {
return null;
}

@Override
public int size() {
return 0;
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public boolean contains(Object o) {
return false;
}

@Override
public void clear() {

}

@Override
public void preorder() {

}

@Override
public void inorder() {

}

@Override
public void postorder() {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.dataStructure.collections.binaryTree;


public interface CustomBinaryTree<T extends Comparable<T>> {

Node<T> getRoot();

void setRoot(Node<T> root);

// 데이터 제일 마지막에 삽입
boolean add(T data);

// 해당 data와 일치하는 데이터 지우기 맨 마지막 값 삭제하기
boolean remove(T data);

// 검색 메서드
boolean search(T data);

// 중위 순회 출력하기
void inorderTraversal();

// 전위 순회 메서드
void preorderTraversal();

// 후위 순회 메서드
void postorderTraversal();

}
Loading