<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.5">Jekyll</generator><link href="https://jae-ran.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://jae-ran.github.io/" rel="alternate" type="text/html" /><updated>2020-01-28T14:47:33+00:00</updated><id>https://jae-ran.github.io/feed.xml</id><title type="html">Jaeran’s Blog</title><subtitle>꼬물꼬물 코딩공부</subtitle><entry><title type="html">Docker에 대해서</title><link href="https://jae-ran.github.io/Docker/" rel="alternate" type="text/html" title="Docker에 대해서" /><published>2020-01-20T00:00:00+00:00</published><updated>2020-01-20T00:00:00+00:00</updated><id>https://jae-ran.github.io/Docker</id><content type="html" xml:base="https://jae-ran.github.io/Docker/">&lt;h2 id=&quot;도커란&quot;&gt;도커란?&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;도커는 컨테이너 기반의 오픈소스 가상화 플랫폼이다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;i class=&quot;fa fa-question-circle&quot;&gt;&lt;/i&gt;Docker의 사전의미&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;항만 노동자. 항구에서 컨테이너를 나르는 것을 생각하자.&lt;/p&gt;

&lt;p&gt;IT에서 말하는 도커가 최근 빠르게 발전하는 기술로서 유명해진 이유는 바로 &lt;u&gt;컨테이너 기반&lt;/u&gt;이기 때문이다!&lt;/p&gt;

&lt;p&gt;도커 설명을 위해 아래 그림을 보자.
&lt;img src=&quot;https://jae-ran.github.io/images/docker.png&quot; alt=&quot;docker&quot; width=&quot;720&quot; height=&quot;343&quot; /&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;고래 등에 올려진 컨테이너 박스들처럼 프로그램과 실행에 필요한 것들을 컨테이너에 실어둔다.&lt;/li&gt;
  &lt;li&gt;손쉽게 이동한다.&lt;/li&gt;
  &lt;li&gt;이를 통해 어디서나 간단하게 실행할 수 있는 도구와 환경을 제공한다.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;클라우드 플랫폼에 적용하여 자동 확장이 가능하게 하고 서비스를 확장할 수 있다.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;i class=&quot;fa fa-question-circle&quot;&gt;&lt;/i&gt; 이미지란&lt;/strong&gt;
특정 프로세스를 실행하기 위한 환경&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;i class=&quot;fa fa-question-circle&quot;&gt;&lt;/i&gt; 컨테이너란&lt;/strong&gt;&lt;br /&gt;
호스트 운영체제의 커널을 공유하면서 컴퓨팅 자원을 제공하는 os 가상화 기술이다. 이미지가 실행된 상태.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;vm가상머신과-도커docker의-차이&quot;&gt;VM(가상머신)과 도커(docker)의 차이&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/vmanddocker.png&quot; alt=&quot;DockerandVM&quot; width=&quot;800&quot; height=&quot;410&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;가상머신&lt;/code&gt;은 Hypervisor(하이퍼바이저)를 통해 가상화를 제공한다. 하드웨어를 가상화 하고,그 위에 GuestOS가 올라간다. 원래 컴퓨터 OS(호스트 OS)위에서 독립된 게스트OS가 돌아가기 때문에 용량이 커지고 실제 호스트 머신에 비해 훨씬 느리다.&lt;/p&gt;

&lt;p&gt;게스트 OS안에 항상 운영체제를 설치해야 한다.&lt;/p&gt;

&lt;p&gt;반면 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;도커&lt;/code&gt;는 하이퍼바이저 없이 실행되는 가상화 솔루션이다.
즉, Guest 운영체제를 설치하지 않고 Docker-engine위에 애플리케이션 실행에 필요한 바이너리만 올라가기 때문에 가상머신보다 훨씬 가볍고 빠르다.&lt;/p&gt;

&lt;p&gt;도커의 컨테이너 이미지에는 운영체제가 포함되지 않는다. 운영체제의 자원은 호스트의 자원을 그대로 이용한다.(Host OS를 공유)&lt;/p&gt;

&lt;p&gt;이렇게 되면 이미지 용량이 매우 줄어들게 되고, 그만큼 네트워크를 덜 쓸 수 있어 빨라지고 배포에도 부담이 없게 된다.&lt;/p&gt;

&lt;p&gt;host가 하나가 아니라 Clustering 환경(여러 host를 하나의 컴퓨터처럼 사용)에서 배포할 경우도 VM으로 배포한다 생각하면 답답할 것이다.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;도커의-특징&quot;&gt;도커의 특징&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;리눅스 컨테이너 기술을 바탕으로 애플리케이션을 격리된 상태에서 실행하는 가상화 솔루션&lt;/li&gt;
  &lt;li&gt;호스트의 운영체제를 공유해 필요한 최소한의 리소스만 할당받아 동작하기 때문에 가볍다.&lt;/li&gt;
  &lt;li&gt;플랫폼에 상관없이 실행될 수 있는 애플리케이션 컨테이너를 만들기 때문에 환경을 구축하는 것이 비약적으로 편해진다.&lt;/li&gt;
  &lt;li&gt;git에서 소스 코드를 올리고 받는 기능과 같이 push/pull 기능을 사용해 이미지를 올리고 받을 수 있다.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;참고&quot;&gt;참고&lt;/h2&gt;
&lt;p&gt;도커/쿠버네티스를 활용한 컨테이너 개발 실전입문&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://sarc.io/index.php/cloud/728-what-is-docker&quot;&gt;https://sarc.io/index.php/cloud/728-what-is-docker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.botmetric.com/blog/containerized-application-deployment-aws-docker-cloud/&quot;&gt;https://www.botmetric.com/blog/containerized-application-deployment-aws-docker-cloud/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://kyulingcompany.wordpress.com/2017/06/22/%EA%B0%80%EC%83%81%EB%A8%B8%EC%8B%A0%EA%B3%BC-%EB%8F%84%EC%BB%A4%EC%9D%98-%EC%B0%A8%EC%9D%B4-%EC%84%B1%EB%8A%A5%EC%9D%98-%EA%B0%80%EB%B2%BC%EC%9B%80/&quot;&gt;Kyuling Company&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://medium.com/@darkrasid/docker%EC%99%80-vm-d95d60e56fdd&quot;&gt;https://medium.com/@darkrasid/docker%EC%99%80-vm-d95d60e56fdd&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="docker" /><category term="cloud" /><summary type="html">도커란? 도커는 컨테이너 기반의 오픈소스 가상화 플랫폼이다.</summary></entry><entry><title type="html">OpenStack에 대해서</title><link href="https://jae-ran.github.io/OpenStack/" rel="alternate" type="text/html" title="OpenStack에 대해서" /><published>2020-01-19T00:00:00+00:00</published><updated>2020-01-19T00:00:00+00:00</updated><id>https://jae-ran.github.io/OpenStack</id><content type="html" xml:base="https://jae-ran.github.io/OpenStack/">&lt;h2 id=&quot;오픈스택이란&quot;&gt;오픈스택이란?&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;www.openstack.org&quot;&gt;오픈스택 공식 사이트&lt;/a&gt;에 따르면 오픈스택이란 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Open Source software for creating private and public clouds&lt;/code&gt;이라고 정의 할 수 있다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;즉, 공용(public) 클라우드와 사설(private) 클라우드 구축을 가능하게 하는 IaaS 역할을 하는 OSS(오픈 소스 소프트웨어)이다.&lt;/p&gt;

&lt;p&gt;OpenStack은 서버, 스토리지, 네트워크들과 같은 자원들을 모두 모아 이들을 제어하고 운영하기 위한 클라우드 Operating System이다.&lt;/p&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;서비스&quot;&gt;서비스&lt;/h2&gt;
&lt;p&gt;오픈스택은 기능에 따라 구성 요소가 분리되어 있다. 주로 사용되는 서비스에 대해 살펴보자.&lt;/p&gt;

&lt;h4 id=&quot;-novacloud-compute-service&quot;&gt;&lt;i class=&quot;fa fa-cogs&quot;&gt;&lt;/i&gt; NOVA(Cloud Compute Service)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;가상머신 라이프사이클 관리자&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;클라우드 IaaS 구축에 필요한 컴퓨팅 자원을 제공하고 관리하는 서비스이다. 오픈스택에서 가장 핵심적인 프로젝트로 가상머신의 생성, 갱신, 삭제, 생명주기 관리 기능을 제공한다.&lt;/p&gt;

&lt;p&gt;다수의 Hypervisor를 지원하여 KVM, Hyper-V, VMWare 등을 사용할 수 있다.&lt;/p&gt;

&lt;p&gt;AWS의 EC2와 호환된 API를 제공한다.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;i class=&quot;fa fa-question-circle&quot;&gt;&lt;/i&gt; Hypervisor?&lt;/strong&gt;
쉽게 말하면 가상화OS이다. 호스트 컴퓨터 1대에서 다수의 운영체제를 동시에 실행할 수 있는 가상 플랫폼 기술을 말한다. 가상화 머신 모니터(VMM)라고도 말한다.&lt;/p&gt;

&lt;h4 id=&quot;-cinderblocked-storage-service&quot;&gt;&lt;i class=&quot;fa fa-database&quot;&gt;&lt;/i&gt; Cinder(Blocked Storage Service)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;블록(Block)기반 스토리지 서비스.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;범용의 저장장치를 기반으로 디스크 볼륨을 제공.&lt;/p&gt;

&lt;p&gt;Cinder에 의해 생성된 가상 디스크 볼륨은 가상머신에 마운트 되어 가상머신 사용자의 데이터를 저장하는데 사용될 수 있다.&lt;/p&gt;

&lt;p&gt;Nova에서 생성된 인스턴스에 확장하여 사용할 수 있는 저장 공간을 생성 및 삭제하고 인스턴스에 연결할 수 있는 기능을 제공한다.&lt;/p&gt;

&lt;h4 id=&quot;-swiftcloud-storage-service&quot;&gt;&lt;i class=&quot;fa fa-archive&quot;&gt;&lt;/i&gt; Swift(Cloud Storage Service)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;오브젝트(Object) 스토리지 서비스.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;대용량 데이터를 저장할 수 있는 높은 확장성을 가지는 오브젝트 저장장치를 제공하는 서비스이다.&lt;/p&gt;

&lt;h4 id=&quot;-horizondashboard-service&quot;&gt;&lt;i class=&quot;fa fa-desktop&quot;&gt;&lt;/i&gt; Horizon(Dashboard Service)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;웹 기반의 대시보드 서비스.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;오픈스택에서 일어나는 서비스에 대한 인터페이스를 웹 베이스로 제공한다. VM을 생성하거나 IP를 지정하는 등의 서비스를 CLI가 아닌 웹에서 사용자가 직접 실행할 수 있도록 도와주는 툴이다.&lt;/p&gt;

&lt;p&gt;아파치 웹 서버를 사용하며, 대시보드는 파이썬 장고 프레임워크로 구현되어 있다.&lt;/p&gt;

&lt;h4 id=&quot;-keysotneidentity-service-keystone&quot;&gt;&lt;i class=&quot;fa fa-unlock-alt&quot;&gt;&lt;/i&gt; Keysotne(Identity Service Keystone)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;오픈스택 서비스들을 위한 통합 인증 시스템.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;사용자 및 API에 대한 인증 및 권한 설정 서비스를 제공한다.&lt;/p&gt;

&lt;h4 id=&quot;-glancecloud-image-service&quot;&gt;&lt;i class=&quot;fa fa-image&quot;&gt;&lt;/i&gt; Glance(Cloud Image Service)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;가상 디스크 이미지들을 저장/등록/관리/전달 할 수 있게 하는 오픈 소스.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;다양한 하이퍼바이저에서 사용할 수 있는 가상 머신 이미지를 관리하고 가상머신에 설치 된 운영체제를 보관 및 관리한다.&lt;/p&gt;

&lt;p&gt;Swift 프로젝트의 오브젝트 저장장치를 포함한 가상 머신 이미지 저장소로부터 가상머신 이미지를 탐색, 등록 및 추출하는 기능을 제공한다.&lt;/p&gt;

&lt;p&gt;Nova를 통해 생성되는 가상 머신은 Glance를 통해 가상 머신 이미지를 제공받고 관리한다.&lt;/p&gt;

&lt;h4 id=&quot;-neutronnetwork-service&quot;&gt;&lt;i class=&quot;fa fa-network-wired&quot;&gt;&lt;/i&gt; Neutron(Network Service)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;소프트웨어 기반의 네트워킹 서비스를 제공.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;VLAN, Router등을 생성하고 변경하거나 삭제한다. Load Valancing, 방화벽, VPN 등을 제공하기도 한다.&lt;/p&gt;

&lt;p&gt;네트워킹 기능은 Neutron과 연결된 네트워크 프로바이더에 의해 제공된다.&lt;/p&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;출처&quot;&gt;출처&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.ibm.com/kr-ko/cloud/products#934716&quot;&gt;https://www.ibm.com/kr-ko/cloud/products#934716&lt;/a&gt;
&lt;a href=&quot;https://sarc.io/index.php/cloud/736-openstack-series-1-openstack&quot;&gt;https://sarc.io/index.php/cloud/736-openstack-series-1-openstack&lt;/a&gt;
&lt;a href=&quot;https://www.dellemc.com/ko-kr/glossary/object-storage.htm&quot;&gt;https://www.dellemc.com/ko-kr/glossary/object-storage.htm&lt;/a&gt;
&lt;a href=&quot;http://liwonace.co.kr/openstack/&quot;&gt;http://liwonace.co.kr/openstack/&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="openstack" /><category term="cloud" /><summary type="html">오픈스택이란? 오픈스택 공식 사이트에 따르면 오픈스택이란 Open Source software for creating private and public clouds이라고 정의 할 수 있다.</summary></entry><entry><title type="html">선택정렬(Selection Sort)</title><link href="https://jae-ran.github.io/SelectionSort/" rel="alternate" type="text/html" title="선택정렬(Selection Sort)" /><published>2019-10-24T00:00:00+00:00</published><updated>2019-10-24T00:00:00+00:00</updated><id>https://jae-ran.github.io/SelectionSort</id><content type="html" xml:base="https://jae-ran.github.io/SelectionSort/">&lt;h2 id=&quot;선택정렬selection-sort-알아보기&quot;&gt;선택정렬(Selection Sort) 알아보기&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;주어진 자료에서 첫 번째 자료를 가지고 두 번째 자료부터 마지막 자료까지 최솟값을 찾는다.&lt;/li&gt;
  &lt;li&gt;그리고 첫번째 위치한 값과 교환한다.(1회전)&lt;/li&gt;
  &lt;li&gt;다음 회전에서 두번째 자료를 남은 값 중에서 비교하고 최솟값과 교환한다.&lt;/li&gt;
  &lt;li&gt;이러한 과정을 반복한다.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;선택정렬의-특징&quot;&gt;선택정렬의 특징&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;장점
    &lt;ul&gt;
      &lt;li&gt;구현이 쉽다고 &lt;u&gt;불안정 정렬&lt;/u&gt;이다.&lt;/li&gt;
      &lt;li&gt;작은 값을 선택하기 위해 비교 횟수는 많지만 교환 횟수는 매우 적은것이 장점이다.&lt;/li&gt;
      &lt;li&gt;따라서 데이터량이 적거나 내림차순에서 오름차순을 하는 자료상태에 성능이 좋다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;단점
    &lt;ul&gt;
      &lt;li&gt;데이터량이 많으면 속도가 매우 떨어진다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;선택정렬-구현&quot;&gt;선택정렬 구현&lt;/h2&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;java.util.Arrays&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SelectionSort&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++){&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++){&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]){&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

      &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

      &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)+&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;회전 후 : &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Arrays&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="java" /><category term="selection" /><summary type="html">선택정렬(Selection Sort) 알아보기</summary></entry><entry><title type="html">Heap정렬(Heap Sort)</title><link href="https://jae-ran.github.io/heapSort/" rel="alternate" type="text/html" title="Heap정렬(Heap Sort)" /><published>2019-10-24T00:00:00+00:00</published><updated>2019-10-24T00:00:00+00:00</updated><id>https://jae-ran.github.io/heapSort</id><content type="html" xml:base="https://jae-ran.github.io/heapSort/">&lt;h2 id=&quot;heap이란&quot;&gt;Heap이란?&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;Heap 정렬은 &lt;b&gt;완전 이진 트리&lt;/b&gt;를 기본으로 하는 힙(Heap) 자료구조를 기반으로 한 정렬 방식이다. 완전 이진 트리는 삽입할 때 왼쪽부터 차례대로 추가하는 이진 트리를 말한다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;다음 두 가지 힙의 종류가 있다.(부모-자식 관계)&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;최대 힙(Max heap): 각 노드의 값은 자식노드의 값보다 크거나 같은 완전 이진 트리.(부모 값 &amp;gt; 자식 값)&lt;/li&gt;
  &lt;li&gt;최소 힙(Min heap): 각 노드의 값은 자식 노드의 값보다 작거나 같은 완전 이진 트리.(부모 값 &amp;lt; 자식 값)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/Heap_MAX_MIN.jpg&quot; alt=&quot;heap&quot; width=&quot;560&quot; height=&quot;280&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;heap정렬heap-sort-알아보기&quot;&gt;Heap정렬(Heap Sort) 알아보기&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;정렬해야 할 n개의 요소들로 최대 힙(완전 이진 트리 형태)을 만든다.(내림차순을 기준으로 정렬)&lt;/li&gt;
  &lt;li&gt;그 다음으로 한 번에 하나씩 요소를 힙에서 꺼내서 배열의 뒤부터 저장하면 된다.&lt;/li&gt;
  &lt;li&gt;삭제 방법(최댓값부터 삭제)을 통해 정렬을 진행한다.&lt;/li&gt;
&lt;/ol&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;heap정렬의-특징&quot;&gt;Heap정렬의 특징&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;특징
    &lt;ul&gt;
      &lt;li&gt;완전 이진 트리의 일종으로 우선순위 큐를 위하여 만들어진 자료구조이다.&lt;/li&gt;
      &lt;li&gt;내림차순 정렬을 위해서는 최대 힙을 구성하고 오름차순 정렬을 위해서는 최소 힙을 구성하면 된다.&lt;/li&gt;
      &lt;li&gt;힙 트리에서는 중복된 값을 허용한다. (이진 탐색 트리에서는 중복된 값을 허용하지 않는다.)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;heap정렬-구현&quot;&gt;Heap정렬 구현&lt;/h2&gt;
&lt;p&gt;❝&lt;br /&gt;
다음의 데이터를 오름차순 정렬하세요.&lt;br /&gt;
&lt;u&gt;7 6 5 8 3 5 9 1 6&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;span style=&quot;color:gray&quot;&gt; 1단계. 주어진 요소들의 배열을 최대힙/ 최소힙으로 만든다.(이번 예제는 최대힙)&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;주어진 데이터를 완전 이진 트리로 표현하면 다음과 같다. 정렬할 데이터를 완전 이진 트리에 삽입 되는 순서대로 인덱스를 붙여준다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/Heap1.JPG&quot; alt=&quot;heap&quot; width=&quot;500&quot; height=&quot;390&quot; /&gt;&lt;/p&gt;

&lt;p&gt;정렬을 하기 위해 완전이진 트리를 최대힙으로 만들어준다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/Heap2.JPG&quot; alt=&quot;heap&quot; width=&quot;815&quot; height=&quot;320&quot; /&gt;
먼저 &lt;b&gt;4번째 노드&lt;/b&gt;부터 본다. 부모의 값(7)이 자식값보다 작다. 15, 14 모두 7보다 크므로 자식값(15,14)을 비교하여 &lt;u&gt;큰값(15)&lt;/u&gt;과 자리를 바꾼다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/Heap3.JPG&quot; alt=&quot;heap&quot; width=&quot;815&quot; height=&quot;320&quot; /&gt;
&lt;b&gt;3번째 노드&lt;/b&gt;를 볼차례다. 부모의 값(3)이 자식값보다 작다. 11, 13 모두 3보다 크므로 자식값(11,13)을 비교하여 &lt;u&gt;큰값(13)&lt;/u&gt;과 자리를 바꾼다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/Heap4.JPG&quot; alt=&quot;heap&quot; width=&quot;815&quot; height=&quot;320&quot; /&gt;
&lt;b&gt;2번째 노드&lt;/b&gt;를 볼차례다. 부모의 값(5)이 자식값 15보다 작다. 따라서 5와 15의 자리를 바꿔준다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/Heap5.JPG&quot; alt=&quot;heap&quot; width=&quot;815&quot; height=&quot;320&quot; /&gt;
4번째 노드가 바뀌었으니 다시 한 번 살펴보자. 4번째 노드 값(5)은 자식 노드(7,14)보다 작기 때문에 최대힙을 만족하지 않으므로 자식값중(7,14) &lt;u&gt;큰값(14)&lt;/u&gt;과 자리를 바꾼다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/Heap6.JPG&quot; alt=&quot;heap&quot; width=&quot;780&quot; height=&quot;350&quot; /&gt;
이제 마지막으로 &lt;b&gt;첫번째 노드&lt;/b&gt;를 확인한다. 그리고 마찬가지로 최대힙을 만족하기 위해 교환해주면 결과가 위의 오른쪽 트리와 같다.&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;span style=&quot;color:gray&quot;&gt; 2단계. 삭제 방법 &lt;/span&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;힙정렬 1단계가 끝나고, 이를 배열과 완전 이진 트리로 나타내면 다음과 같다.
&lt;img src=&quot;https://jae-ran.github.io/images//Heap1_End.JPG&quot; alt=&quot;heap&quot; width=&quot;500&quot; height=&quot;460&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;2-1단계) 맨 마지막 노드와 루트노드를 교환한다.&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/Heap2_1.JPG&quot; alt=&quot;heap&quot; width=&quot;815&quot; height=&quot;320&quot; /&gt;&lt;/p&gt;

&lt;p&gt;위와 같이 15와 14를 바꾼 뒤 15는 정렬이 완료된 것으로 생각한다.(노드가 “없다”고 생각)&lt;/p&gt;

&lt;p&gt;&lt;b&gt;2-2단계) 현재 루트노드에 대해 다운힙을 진행한다.&lt;/b&gt;&lt;br /&gt;
이는 최대힙을 만드는 과정과 같다.&lt;/p&gt;

&lt;p&gt;루트노드(5)와 5의 자식인 14, 13을 비교한다. 가장 큰 자식 14와 바꾸어준다. 5가 자기자리를 찾아가도록 이와 같은 방법을 반복..&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/Heap2_2.JPG&quot; alt=&quot;heap&quot; width=&quot;815&quot; height=&quot;320&quot; /&gt;&lt;/p&gt;

&lt;p&gt;다운힙을 진행한 결과, 이제 다시 가장 큰 숫자인 14가 루트에 존재한다. 이를 가장 뒤 쪽의 원소와 서로 바꾼다.(2-1 단계)&lt;br /&gt;
현재 루트노드(1)에 대해 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;다운힙&lt;/code&gt;(2-2단계)을 진행한다.&lt;/p&gt;

&lt;p&gt;이렇게 2단계 과정을 계속해서 반복해주면 정렬이 완료된다.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;출처&quot;&gt;출처&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://gmlwjd9405.github.io/2018/05/10/data-structure-heap.html&quot;&gt;https://gmlwjd9405.github.io/2018/05/10/data-structure-heap.html&lt;/a&gt;
&lt;a href=&quot;https://zeddios.tistory.com/56&quot;&gt;https://zeddios.tistory.com/56&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="java" /><category term="Heap" /><summary type="html">Heap이란? Heap 정렬은 완전 이진 트리를 기본으로 하는 힙(Heap) 자료구조를 기반으로 한 정렬 방식이다. 완전 이진 트리는 삽입할 때 왼쪽부터 차례대로 추가하는 이진 트리를 말한다.</summary></entry><entry><title type="html">삽입정렬(Insert Sort)</title><link href="https://jae-ran.github.io/insertionSort/" rel="alternate" type="text/html" title="삽입정렬(Insert Sort)" /><published>2019-10-24T00:00:00+00:00</published><updated>2019-10-24T00:00:00+00:00</updated><id>https://jae-ran.github.io/insertionSort</id><content type="html" xml:base="https://jae-ran.github.io/insertionSort/">&lt;h2 id=&quot;삽입정렬insert-sort-알아보기&quot;&gt;삽입정렬(Insert Sort) 알아보기&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;두 번째 자료부터 시작하여 그 앞(왼쪽)의 자료들과 비교하여 삽입할 위치를 지정한 후 자료를 뒤로 옮기고 지정한 자리에 자료를 삽입하여 정렬하는 알고리즘이다.&lt;/li&gt;
  &lt;li&gt;즉, 두 번째 자료는 첫 번째 자료, 세 번째 자료는 두 번째와 첫 번째 자료, 네 번째 자료는 세 번째, 두 번째, 첫 번째 자료와 비교한 후 자료가 삽입될 위치를 찾는다. 자료가 삽입될 위치를 찾았다면 그 위치에 자료를 삽입하기 위해 자료를 한 칸씩 뒤로 이동시킨다.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;삽입정렬의-특징&quot;&gt;삽입정렬의 특징&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;장점
    &lt;ul&gt;
      &lt;li&gt;삽입정렬은 기본적으로 버블정렬의 비교횟수를 줄인다, 안정 정렬이다.&lt;/li&gt;
      &lt;li&gt;비교적 크기가 작은 데이터 집합의 정렬에 유리하고, 이미 정렬되어 있는 경우 최적의 경우이다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;단점
    &lt;ul&gt;
      &lt;li&gt;비교적 이동 횟수가 많다.&lt;/li&gt;
      &lt;li&gt;데이터 집합이 많고 길수록 효율이 떨어진다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;삽입정렬-구현&quot;&gt;삽입정렬 구현&lt;/h2&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;java.util.Arrays&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;InsertSort&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;};&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;insertSort&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;insertSort&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++){&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Key값 = 삽입대상&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]){&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// 이동&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;--;&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)+&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;회전 후 : &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Arrays&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="java" /><category term="insert" /><summary type="html">삽입정렬(Insert Sort) 알아보기</summary></entry><entry><title type="html">버블정렬(Bubble Sort)</title><link href="https://jae-ran.github.io/BubbleSort/" rel="alternate" type="text/html" title="버블정렬(Bubble Sort)" /><published>2019-10-23T00:00:00+00:00</published><updated>2019-10-23T00:00:00+00:00</updated><id>https://jae-ran.github.io/BubbleSort</id><content type="html" xml:base="https://jae-ran.github.io/BubbleSort/">&lt;h2 id=&quot;버블정렬bubble-sort-알아보기&quot;&gt;버블정렬(Bubble Sort) 알아보기&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;첫 번째 자료와 두 번째 자료를, 두 번째 자료와 세 번째 자료를, 세 번째와 네 번째를, … 이런 식으로 (마지막-1)번째 자료와 마지막 자료를 비교하여 교환하면서 자료를 정렬한다. -&amp;gt; 서로 인접한 두 원소를 비교한다.&lt;/li&gt;
  &lt;li&gt;1회전을 수행하고 나면 가장 큰 자료가 맨 뒤로 이동하므로 2회전에서는 맨 끝에 있는 자료는 정렬에서 제외되고, 2회전을 수행하고 나면 끝에서 두 번째 자료까지는 정렬에서 제외된다. 이렇게 정렬을 1회전 수행할 때마다 정렬에서 제외되는 데이터가 하나씩 늘어난다. -&amp;gt; 인접한 두 원소가 순서대 되어있지 않으면 교환한다.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;버블정렬의-특징&quot;&gt;버블정렬의 특징&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;장점
    &lt;ul&gt;
      &lt;li&gt;구현이 간단하고 &lt;u&gt;안전 정렬&lt;/u&gt;이다.&lt;/li&gt;
      &lt;li&gt;데이터를 하나씩 비교하여 정밀하다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;단점
    &lt;ul&gt;
      &lt;li&gt;하지만 비교횟수가 너무 많아지고 비효율적이여서 잘 쓰이지 않는다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;i class=&quot;fa fa-question-circle&quot;&gt;&lt;/i&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;안전 정렬과 불안정 정렬&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt; 안정 정렬 &lt;/b&gt;: 동일한 값에 대해 기존의 순서가 유지되는 정렬 방식&lt;br /&gt;
&lt;b&gt;불안정 정렬 &lt;/b&gt;: 동일한 값에 대해 기존의 순서가 유지되지 않는 정렬 방식&lt;/p&gt;
&lt;/blockquote&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;버블정렬-구현&quot;&gt;버블정렬 구현&lt;/h2&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;java.util.Arrays&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;BubbleSort&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;bubbleSort&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;bubbleSort&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++){&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++){&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]){&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;회전 후 : &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Arrays&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="java" /><category term="bubble" /><summary type="html">버블정렬(Bubble Sort) 알아보기</summary></entry><entry><title type="html">Hash에 대해서</title><link href="https://jae-ran.github.io/Hash/" rel="alternate" type="text/html" title="Hash에 대해서" /><published>2019-10-23T00:00:00+00:00</published><updated>2019-10-23T00:00:00+00:00</updated><id>https://jae-ran.github.io/Hash</id><content type="html" xml:base="https://jae-ran.github.io/Hash/">&lt;h2 id=&quot;hash란&quot;&gt;Hash란?&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;특정한 데이터를 이를 상징하는 더 짧은 길이의 데이터로 변환하는 행위이다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/HashTable.png&quot; alt=&quot;HashTeble&quot; width=&quot;400&quot; height=&quot;300&quot; /&gt;&lt;/p&gt;

&lt;p&gt;내부적인 배열을 사용하여 데이터를 저장하는 자료구조로 검색과 저장이 매우 빠르다.&lt;/p&gt;

&lt;p&gt;데이터를 검색할 때 &lt;b&gt;key&lt;/b&gt;를 통해 &lt;u&gt;고유의 인덱스&lt;/u&gt;로 접근하기 때문에 빠르게 진행될 수 있는 것이다. 항상 그런 것은 아니지만 검색과 저장의 평균적인 시간 복잡도는 O(1)이다.&lt;/p&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;hash-table해시-테이블&quot;&gt;Hash Table(해시 테이블)&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;해시함수를 이용하여 키를 해시값으로 매핑하고, 이 해시값을 색인(index) 혹은 주소 삼아 데이터의 값(value)을 키와 함께 저장하는 자료구조를 &lt;b&gt;해시테이블(hash table)&lt;/b&gt;이라고 한다.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;hash-function해시-함수&quot;&gt;Hash Function(해시 함수)&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;b&gt;해시함수&lt;/b&gt;란 데이터의 효율적인 관리를 목적으로 임의의 저장할 데이터를 고유한 숫자 데이터로 매핑하는 함수이다. 매핑 전 원래 데이터 값을 &lt;b&gt;키(key)&lt;/b&gt;라 하고, 매핑 후 데이터 값을 &lt;b&gt;해시값(hash value)&lt;/b&gt;이라 한다. 이러한 매핑 과정을 &lt;b&gt;해싱(hashing)&lt;/b&gt;이라 한다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;하지만 해시함수는 &lt;u&gt;두 개의 서로다른 키에 대해 동일한 해시값을 내는&lt;/u&gt; &lt;b&gt;해시충돌(collision)&lt;/b&gt;이 발생할 수 있다. 그렇게되면 같은 곳에 저장할 수 없게된다.&lt;/p&gt;

&lt;p&gt;Collision이 많아질수록 Search에 필요한 시간복잡도가 O(1)에서 O(n)에 가까워진다. 해시충돌이 발생할 가능성이 있음에도 해시테이블을 쓰는 이유는 적은 리소스로 많은 데이터를 효율적으로 관리하기 위해서이다. 예컨대 해시함수로 하드디스크나 클라우드에 존재하는 무한에 가까운 데이터(키)들을 유한한 개수의 해시값으로 매핑함으로써 작은 크기의 캐쉬 메모리로도 프로세스를 관리할 수 있게 된다.&lt;/p&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;collision-해결&quot;&gt;Collision 해결&lt;/h2&gt;
&lt;p&gt;기본적인 두 방법을 알아보자.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;Open Address 방식(개방주소법)&lt;/b&gt;&lt;br /&gt;
 해시 충돌이 일어나면, 다른 해시 버킷(bucket)에 해당 자료를 삽입하는 방식이다. 정해진 해시테이블내에서만 저장되므로 &lt;b&gt;Closed Hashing(폐쇄 해싱)&lt;/b&gt;이라고도 한다. 대표적으로 세가지 방식이 있다.
    &lt;ol&gt;
      &lt;li&gt;선형탐색(Linear Probing) : 해시충돌 시 순차적으로 탐색하여 비어있는 버킷에 데이터를 삽입한다.&lt;/li&gt;
      &lt;li&gt;제곱 탐색(Quadratic Probing) :  해시충돌 시 제곱만큼 건너뛴 버킷에 데이터를 삽입한다. Ex)1,4,9,16 …&lt;/li&gt;
      &lt;li&gt;이중 해시(Double Hashing) : 해시충돌 시 다른 해시함수를 한 번 더 적용한 결과를 이용한다.
&lt;img src=&quot;https://jae-ran.github.io/images/closedHashing.JPG&quot; alt=&quot;HashTable&quot; width=&quot;180&quot; height=&quot;450&quot; /&gt;&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;b&gt;Separate Chaining 방식(분리연결법)&lt;/b&gt;&lt;br /&gt;
 해시 충돌이 일어나면, 주어진 &lt;u&gt;해시테이블 공간외에 새로운 공간을 할당&lt;/u&gt;하는 방법이다.
 &lt;b&gt;Open Hashing(개방해싱)&lt;/b&gt;이라고도 한다. 대표적으로 두가지 방식이 있다.
    &lt;ol&gt;
      &lt;li&gt;연결 리스트를 사용하는 방식(Linked List)
각각의 버킷들을 연결리스트(Linked List)로 만들어 Collision이 발생하면 해당 버킷의 list에 추가하는 방식이다. 연결 리스트의 특징을 그대로 이어받아 삭제 또는 삽입이 간단하지만 작은 데이터들을 저장할 때 연결 리스트 자체의 오버헤드가 부담된다.&lt;/li&gt;
      &lt;li&gt;Tree를 사용하는 방식 (Red-Black Tree)
연결 리스트 대신 트리를 사용하는 방식이다. 연결 리스트를 사용할지 트리를 사용할지에 대한 기준은 하나의 버킷에 할당된 key-value 쌍의 개수이다. 데이터 개수가 적다면(6개, 8개) 링크드 리스트를 사용하는 것이 맞다. 트리는 기본적으로 메모리 사용량이 많기 때문이다.
&lt;img src=&quot;https://jae-ran.github.io/images/openHashing.JPG&quot; alt=&quot;HashTable&quot; width=&quot;300&quot; height=&quot;390&quot; /&gt;&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;b&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Open Address&lt;/code&gt; VS &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Separate Chaining&lt;/code&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Open Address 방식(개방주소법):&lt;/b&gt; 연결된 공간에 데이터를 저장하기 때문에 분리연결법에 비해 &lt;u&gt;캐시효율이 높다.&lt;/u&gt; 따라서 데이터의 개수가 충분히 적다면 개방주소법 방식이 성능이 더 좋다.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Separate Chaining 방식(분리연결법):&lt;/b&gt; 개방주소법은 분리연결법에 비해 버킷을 계속해서 사용한다. 따라서 분리연결법 방식은 테이블의 확장을 보다 늦출 수 있다.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;u&gt;테이블의 확장&lt;/u&gt;은 매우 심각한 성능의 저하를 나타낸다. 가급적 확장을 하지 않도록 테이블을 설계하고 제어하는 방법이 필요하다.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;출처&quot;&gt;출처&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://ratsgo.github.io/data%20structure&amp;amp;algorithm/2017/10/25/hash/&quot;&gt;https://ratsgo.github.io/data%20structure&amp;amp;algorithm/2017/10/25/hash/&lt;/a&gt;
 &lt;a href=&quot;https://k39335.tistory.com/18&quot;&gt;https://k39335.tistory.com/18&lt;/a&gt;
 &lt;a href=&quot;https://preamtree.tistory.com/20&quot;&gt;https://preamtree.tistory.com/20&lt;/a&gt;
 &lt;a href=&quot;https://galid1.tistory.com/170&quot;&gt;https://galid1.tistory.com/170&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="java" /><category term="Hash" /><summary type="html">Hash란? 특정한 데이터를 이를 상징하는 더 짧은 길이의 데이터로 변환하는 행위이다.</summary></entry><entry><title type="html">OOP에 대해서</title><link href="https://jae-ran.github.io/JavaOOP/" rel="alternate" type="text/html" title="OOP에 대해서" /><published>2019-09-12T00:00:00+00:00</published><updated>2019-09-12T00:00:00+00:00</updated><id>https://jae-ran.github.io/JavaOOP</id><content type="html" xml:base="https://jae-ran.github.io/JavaOOP/">&lt;h2 id=&quot;객체-지향-프로그래밍oopobject-oriented-programming-이란&quot;&gt;객체 지향 프로그래밍(OOP:Object Oriented Programming) 이란?&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;객체 지향 프로그래밍(이하 OOP)는 말 그대로 “객체(Object)”를 이용해서 프로그램을 설계하는 방법론 중 하나이다. 프로그램(실제세계)를 객체(사물)라는 기본 단위로 나누고 이 객체들간의 상호작용을 기본개념으로 한다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;OOP는 크게 4가지 특징을 가진다.&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;abstraction(추상화)&lt;/li&gt;
  &lt;li&gt;Polymorphism(다형성)&lt;/li&gt;
  &lt;li&gt;Encapsulation(캡슐화, 은닉화)&lt;/li&gt;
  &lt;li&gt;Inheritance(상속성)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;i class=&quot;fa fa-question-circle&quot;&gt;&lt;/i&gt;  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;객체&lt;/code&gt;란 무엇일까&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;객체&lt;/b&gt;란 주변에 존재하는 모든 사물, 생명체를 의미한다. 각자 &lt;u&gt;상태와 행동&lt;/u&gt;을 가지고 있어 다른 것과 구별이 가능하고, 자바에서는 이 속성과 동작을 필드(field)와 메소드(method)라 부른다.&lt;/p&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;객체지향-vs-절차지향&quot;&gt;객체지향 VS 절차지향&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/OOP.JPG&quot; alt=&quot;OOP&quot; width=&quot;650&quot; height=&quot;290&quot; /&gt;&lt;/p&gt;

&lt;p&gt;자바는 100% 객체 지향 언어이다. 객체를 만들기 위해 설계도인 클래스를 작성해야 하고, 객체와 객체를 연결하여 목적에 맞는 프로그램을 만들어 낸다.&lt;/p&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;oop의-특징&quot;&gt;OOP의 특징&lt;/h2&gt;

&lt;h4 id=&quot;1-abstraction추상화&quot;&gt;1. abstraction(추상화)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;여러 객체들의 공통된 특성 묶어 상위개념으로 표현&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;중복된 부분들을 묶어 하나의 클래스로 정의하는 것을 말한다.&lt;/p&gt;
&lt;h4 id=&quot;2-polymorphism다형성&quot;&gt;2. Polymorphism(다형성)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;객체를 표현하는 다양한 방식이 존재&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;하나의 클래스, 메소드가 있을 때, 이를 재구성 하여 다양한 방식으로 사용할 수 있도록 하는 것을 의미한다. 하나의 메시지를 전달했을때, 수신자가 메시지의 형식에 따라 일을 수행할 메소드를 정하는 방식을 말한다.&lt;/p&gt;

&lt;p&gt;Ex. 오버로딩, 오버라이딩&lt;/p&gt;
&lt;h4 id=&quot;3-encapsulation캡슐화-은닉화&quot;&gt;3. Encapsulation(캡슐화, 은닉화)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;숨길 부분과 밖으로 드러낼 부분을 조절&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ex. 접근지정자(private, protected, public)&lt;/p&gt;
&lt;h4 id=&quot;4-inheritance상속성&quot;&gt;4. Inheritance(상속성)&lt;/h4&gt;
&lt;blockquote&gt;
  &lt;p&gt;부모객체를 상속해서 자식객체를 만듬.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;자식 클래스가 부모 클래스를 상속 받으면 자식 클래스는 부모 클래스에서 접근 지정자에 의해 허용된 범위 내 메소드나 데이터에 접근이 가능하다. 상속을 통해 코드의 재사용에 유용하다. 하지만 특정 메소드 재사용만을 위해 상속을 받는 것은 클래스간 관계를 어지럽게 하기 때문에 지양해야 한다.&lt;/p&gt;

&lt;p&gt;자바에서 다중상속은 허용하지 않는다. 하지만 interface를 implement해서 다중상속의 효과를 얻을 수 있다.&lt;/p&gt;

&lt;p&gt;Ex. extends 키워드&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;참조&quot;&gt;참조&lt;/h2&gt;
&lt;p&gt;이것이 자바다.
&lt;a href=&quot;https://blog.naver.com/2feelus/220642212134&quot;&gt;https://blog.naver.com/2feelus/220642212134&lt;/a&gt;
&lt;a href=&quot;https://velog.io/@cyranocoding/%EA%B0%9D%EC%B2%B4-%EC%A7%80%ED%96%A5-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8DOOP-Object-Oriented-Programming-%EA%B0%9C%EB%85%90-%EB%B0%8F-%ED%99%9C%EC%9A%A9-%EC%A0%95%EB%A6%AC-igjyooyc6c&quot;&gt;https://velog.io/@cyranocoding/%EA%B0%9D%EC%B2%B4-%EC%A7%80%ED%96%A5-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8DOOP-Object-Oriented-Programming-%EA%B0%9C%EB%85%90-%EB%B0%8F-%ED%99%9C%EC%9A%A9-%EC%A0%95%EB%A6%AC-igjyooyc6c&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="객체" /><category term="프로그래밍" /><category term="java" /><summary type="html">객체 지향 프로그래밍(OOP:Object Oriented Programming) 이란? 객체 지향 프로그래밍(이하 OOP)는 말 그대로 “객체(Object)”를 이용해서 프로그램을 설계하는 방법론 중 하나이다. 프로그램(실제세계)를 객체(사물)라는 기본 단위로 나누고 이 객체들간의 상호작용을 기본개념으로 한다.</summary></entry><entry><title type="html">Queue에 대해서</title><link href="https://jae-ran.github.io/Queue/" rel="alternate" type="text/html" title="Queue에 대해서" /><published>2019-09-12T00:00:00+00:00</published><updated>2019-09-12T00:00:00+00:00</updated><id>https://jae-ran.github.io/Queue</id><content type="html" xml:base="https://jae-ran.github.io/Queue/">&lt;h2 id=&quot;queue란&quot;&gt;Queue란?&lt;/h2&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nc&quot;&gt;Queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;queue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;LinkedList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
  &lt;p&gt;선입선출(FIFO:First In First Out)의 자료구조이다. 가장 먼저 저장된(push) 데이터가 가장 먼저 인출(pop)된다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/queue.JPG&quot; alt=&quot;Queue&quot; width=&quot;450&quot; height=&quot;170&quot; /&gt;
큐에서 삭제가 발생하는 곳을 front라 하고, 큐에서 삽입이 발생하는 곳을 rear라고 한다.&lt;/p&gt;

&lt;p&gt;Queue 인터페이스를 상속받은 하위 인터페이스는 다음과 같다.&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Deque&lt;E&gt;&lt;/E&gt;&lt;/li&gt;
  &lt;li&gt;BlockingDeque&lt;E&gt;&lt;/E&gt;&lt;/li&gt;
  &lt;li&gt;BlockingQueue&lt;E&gt;&lt;/E&gt;&lt;/li&gt;
  &lt;li&gt;TransferQueue&lt;E&gt;&lt;/E&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;deque덱&quot;&gt;Deque(덱)&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;자료의 입력과 출력을 양 끝에서 가능하게 한 자료구조로 큐와 스택의 성격을 가지고 있다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;queue-method&quot;&gt;Queue Method&lt;/h2&gt;
&lt;p&gt;Queue 인터페이스는 큐 메모리 구조를 표현하기 위해, 다음과 같은 Collection 인터페이스 메소드만을 상속받아 사용한다.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/QueueMethod.JPG&quot; alt=&quot;QueueMethod&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;queue의-종류&quot;&gt;Queue의 종류&lt;/h2&gt;
&lt;h3 id=&quot;linear-queue선형-큐&quot;&gt;Linear Queue(선형 큐)&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;한 방향으로 데이터 항목들이 삽입/삭제되는 큐, 배열을 선형으로 사용해 큐를 구현한다.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Linear_Queue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;front&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxsize&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Linear_Queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Linear_Queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;maxsize&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Linear_Queue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;maxsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;EnQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;Linear_Queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[++&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;데이터 다참&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;DeQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Linear_Queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;Linear_Queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Linear_Queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;--;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;하지만 선형 큐를 수행 했을 경우 요소들을 하나씩 다 옮겨줘야 하고, 가득 차지 않았는데 rear이 마지막 인덱스를 가리키고있으면 공간이 비어있더라도 연산을 하지 못한다. 즉, 메모리를 효율적으로 관리하지 못한다.&lt;/p&gt;

&lt;h3 id=&quot;circular-queue원형-큐&quot;&gt;Circular Queue(원형 큐)&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;선형 큐의 문제점을 보완하기 위한 자료구조이다. 시작점과 끝점이 서로 연결되어 있는 큐&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;원형큐에서는 포인터 증가 방식이 (rear+1)%arraysize 형식으로 변환하기 때문에 배열의 첫 인덱스부터 다시 데이터의 삽입이 가능해진다.&lt;/p&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Circular_Queue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;              &lt;span class=&quot;c1&quot;&gt;//초기 공백 상태일 때 0에서부터 시작&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;front&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;            &lt;span class=&quot;c1&quot;&gt;//초기 공백 상태일 때 0에서부터 시작&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxsize&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;          &lt;span class=&quot;c1&quot;&gt;//배열의 크기&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;circular_Queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;//배열&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Circular_Queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;maxsize&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;circular_Queue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;maxsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Isempty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;//공백 상태인지 체크&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Isfull&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;//배열이 포화 상태인지 체크&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;maxsize&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;EnQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Isfull&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt;            &lt;span class=&quot;c1&quot;&gt;//배열이 포화상태일경우&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;큐가 가득 찼습니다&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;                &lt;span class=&quot;c1&quot;&gt;//배열이 포화상태가 아닐경우&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maxsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;circular_Queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;DeQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Isempty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;//배열이 공백상태이면 -1반환&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;                 &lt;span class=&quot;c1&quot;&gt;//배열이 공백상태가 아니라면&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;front&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;maxsize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;circular_Queue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;front&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;priority-queue우선순위-큐&quot;&gt;Priority Queue(우선순위 큐)&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;들어온 순서에 관계 없이 데이터를 꺼낼 때, 우선순위가 가장 높은 데이터가 먼저 나오는 큐&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;힙을 이용하여 구현하는것이 일반적이다. 데이터를 삽입할 때 우선순위를 기준으로 최대힙 혹은 최소힙을 구성하고 데이터를 꺼낼 때 루트 노드를 얻어낸다. 루트 노드를 삭제할 때는 빈 루트 노드 위치에 맨 마지막 노드를 삽입한 후 아래로 내려가면서 적절한 자리를 찾아서 옮긴다.&lt;/p&gt;

&lt;p&gt;우선순위를 정하는 기준은 Java의 정렬기준과 동일하다. 기본적으로 오름차순으로 정렬하게 되는데, 우선순위를 변경하고 싶다면 &lt;b&gt;Compartor&lt;/b&gt; 클래스나 &lt;b&gt;Comparable&lt;/b&gt; 인터페이스를 이용한다. &lt;b&gt;Collections.reversOrder()&lt;/b&gt;를 사용해 간편하게 내림차순으로 변경할 수도 있다.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;i class=&quot;fa fa-question-circle&quot;&gt;&lt;/i&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Comparable과 Compartor 차이&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;Comparable&lt;/b&gt;: 기본 정렬기준을 구현할 때 사용.
기본적으로 작은 값에서 큰 값, 오름차순 형태로 구현된다.
Comparable를 implements한 후, compareTo() 메소드를 오버라이드한다.
&lt;br /&gt;&lt;/li&gt;
  &lt;li&gt;&lt;b&gt;Compartor&lt;/b&gt;: 기본 정렬기준 외 다른 기준으로 정렬할 때 사용.
Compartore를 implements한 후, compare 메소드를 오버라이드 한다.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;참조&quot;&gt;참조&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://lktprogrammer.tistory.com/47&quot;&gt;https://lktprogrammer.tistory.com/47&lt;/a&gt;
&lt;a href=&quot;http://tcpschool.com/java/java_collectionFramework_stackQueue&quot;&gt;http://tcpschool.com/java/java_collectionFramework_stackQueue&lt;/a&gt;
&lt;a href=&quot;https://songeunjung92.tistory.com/23&quot;&gt;https://songeunjung92.tistory.com/23&lt;/a&gt;
&lt;a href=&quot;https://freestrokes.tistory.com/83?category=1045118&quot;&gt;https://freestrokes.tistory.com/83?category=1045118&lt;/a&gt;
&lt;a href=&quot;https://eskeptor.tistory.com/98&quot;&gt;https://eskeptor.tistory.com/98&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="java" /><category term="queue" /><summary type="html">Queue란? Queue&amp;lt;E&amp;gt; queue = new LinkedList&amp;lt;E&amp;gt;(); 선입선출(FIFO:First In First Out)의 자료구조이다. 가장 먼저 저장된(push) 데이터가 가장 먼저 인출(pop)된다.</summary></entry><entry><title type="html">Stack에 대해서</title><link href="https://jae-ran.github.io/Stack/" rel="alternate" type="text/html" title="Stack에 대해서" /><published>2019-09-12T00:00:00+00:00</published><updated>2019-09-12T00:00:00+00:00</updated><id>https://jae-ran.github.io/Stack</id><content type="html" xml:base="https://jae-ran.github.io/Stack/">&lt;h2 id=&quot;stack이란&quot;&gt;Stack이란?&lt;/h2&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nc&quot;&gt;Stack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;st&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Stack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
  &lt;p&gt;후입선출(LIFO:Last In First Out)의 자료구조이다. 즉 가장 나중에 저장된(push)데이터가 가장 먼저 인출(pop)된다. 접근이 목록의 끝(Top 또는 Top Pointer)에서만 일어나기 때문에 Pushdown List 라고도 한다&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;https://jae-ran.github.io/images/stack.JPG&quot; alt=&quot;Stack&quot; width=&quot;215&quot; height=&quot;219&quot; /&gt;
Stack 클래스는 List 컬렉션 클래스의 Vector 클래스를 상속받아, 전형적인 스택 메모리 구조의 클래스를 제공한다.&lt;/p&gt;

&lt;p&gt;다음은 스택이 실제로 쓰이는 예이다.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;운영체제(OS: Operating System)
프로그램에서 사용되는 함수들을 스택 자료형에 저장하여 사용한다.&lt;/li&gt;
  &lt;li&gt;컴파일러(Compiler)
수학 기호들을 기계어로 변환시 사용한다. (연산자 우선 순위 표현을 위한 괄호 검사)&lt;/li&gt;
  &lt;li&gt;자바 가상 머신(JVM: Java Virtual Machine)
JVM 내에서 메서드가 실행, 종료될 때 스택 프레임을 이용하여 관리한다.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;stack의-구현&quot;&gt;Stack의 구현&lt;/h2&gt;
&lt;p&gt;스택의 구현 방법은 &lt;b&gt;배열&lt;/b&gt;을 이용하는 것과 &lt;b&gt;연결 리스트를&lt;/b&gt; 사용하는 것 두가지가 있다.&lt;/p&gt;

&lt;h4 id=&quot;1-배열을-활용해-stack-구현해보기&quot;&gt;1. 배열을 활용해 Stack 구현해보기.&lt;/h4&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ArrayStack&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Stack&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stackArray&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 현재 인덱스 확인&lt;/span&gt;

  	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

   	 &lt;span class=&quot;nc&quot;&gt;ArrayStack&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ArrayStack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
   	 &lt;span class=&quot;n&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;hihi&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  	 &lt;span class=&quot;n&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  	 &lt;span class=&quot;n&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;'A'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

  	&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
  	&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
  	&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
  	&lt;span class=&quot;n&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;'A'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  	&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ArrayStack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;stackArray&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stackArray&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;IndexOutOfBoundsException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;full&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;stackArray&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;peek&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;IndexOutOfBoundsException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stackArray&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;IndexOutOfBoundsException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peek&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;stackArray&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;배열을 활용할 경우 구현이 쉽고, 원하는 데이터의 접근 속도가 빠르다. 그러나 데이터 삽입과 삭제에 있어 비효율적이다.&lt;/p&gt;
&lt;h4 id=&quot;2-링크드리스트를-활용한-stack-구현해보기&quot;&gt;2. 링크드리스트를 활용한 Stack 구현해보기.&lt;/h4&gt;
&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;LinkedStack&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Stack&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Stack&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;topNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;nc&quot;&gt;LinkedStack&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ls&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;LinkedStack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;ls&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;ls&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;ls&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;hiih&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

		&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ls&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
		&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ls&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
		&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ls&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;



	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;LinkedStack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;topNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

		&lt;span class=&quot;c1&quot;&gt;// 새로운 노드 생성&lt;/span&gt;
		&lt;span class=&quot;nc&quot;&gt;OdolNode&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;OdolNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;c1&quot;&gt;// 새로운 노드의 다음노드를 삽입 이전의 top을 참조하도록&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setNextNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;topNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;c1&quot;&gt;// 삽입 이후의 탑은 새로운 노드&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;topNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;IndexOutOfBoundsException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;empty&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;c1&quot;&gt;// 탑노드의 데이터&lt;/span&gt;
			&lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;peek&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
			&lt;span class=&quot;c1&quot;&gt;// 새로운 탑노드는 현재 탑노드의 nextNode&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;topNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;topNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getNextNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
			&lt;span class=&quot;c1&quot;&gt;// 데이터 반환&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;peek&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;IndexOutOfBoundsException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;topNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getData&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 데이터만 반환&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;topNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;OdolNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 스택에 활용할 노드 클래스&lt;/span&gt;

	&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 데이터를 저장&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;OdolNode&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nextNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 이전의 노드를 저장하기 위한 노드&lt;/span&gt;

	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;OdolNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;nextNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getData&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;setNextNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;OdolNode&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;nextNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;OdolNode&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getNextNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nextNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;링크드 리스트를 활용할 경우 데이터의 최대 개수가 한정되어 있지 않고, 데이터 삽입 삭제가 용이하다. 연결리스트 구조는 배열과 다르게 데이터가 순차적으로 나열되어 있지 않다.&lt;/p&gt;
&lt;hr /&gt;

&lt;h2 id=&quot;stack-method&quot;&gt;Stack Method&lt;/h2&gt;
&lt;p&gt;Stack 클래스는 스택 메모리 구조를 표현하기 위해, Vector 클래스의 메소드를 5개만 상속받아 사용한다.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;출처&quot;&gt;출처&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://freestrokes.tistory.com/82&quot;&gt;https://freestrokes.tistory.com/82&lt;/a&gt;
&lt;a href=&quot;https://odol87.tistory.com/6&quot;&gt;https://odol87.tistory.com/6&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="java" /><category term="Stack" /><summary type="html">Stack이란? Stack&amp;lt;E&amp;gt; st = new Stack&amp;lt;E&amp;gt;(); 후입선출(LIFO:Last In First Out)의 자료구조이다. 즉 가장 나중에 저장된(push)데이터가 가장 먼저 인출(pop)된다. 접근이 목록의 끝(Top 또는 Top Pointer)에서만 일어나기 때문에 Pushdown List 라고도 한다</summary></entry></feed>