Skip to content

Commit 59f6638

Browse files
authored
Merge pull request #10 from Data-Structure-Study/hamill
[Hamill] feat : Array, ArrayList, LinkedList 로 Stack 구현
2 parents 67a35b7 + 9389b76 commit 59f6638

19 files changed

+470
-59
lines changed

Diff for: .idea/.gitignore

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/java-datastructure.iml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
20.8 KB
Binary file not shown.
0 Bytes
Binary file not shown.

Diff for: hamill/.gradle/5.2.1/fileHashes/fileHashes.bin

650 Bytes
Binary file not shown.

Diff for: hamill/.gradle/5.2.1/fileHashes/fileHashes.lock

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

Diff for: hamill/.idea/uiDesigner.xml

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: hamill/src/main/java/com/codesquad/datastructurestudy/linkedlist/DoublyLinkedList.java

-58
Original file line numberDiff line numberDiff line change
@@ -197,61 +197,3 @@ public void display() {
197197
System.out.println();
198198
}
199199
}
200-
201-
class Link {
202-
/**
203-
* Value of node
204-
*/
205-
public int value;
206-
/**
207-
* This points to the link in front of the new link
208-
*/
209-
public Link next;
210-
/**
211-
* This points to the link behind the new link
212-
*/
213-
public Link previous;
214-
215-
/**
216-
* Constructor
217-
*
218-
* @param value Value of node
219-
*/
220-
public Link(int value) {
221-
this.value = value;
222-
}
223-
224-
/**
225-
* Displays the node
226-
*/
227-
public void displayLink() {
228-
System.out.print(value + " ");
229-
}
230-
231-
/**
232-
* Main Method
233-
*
234-
* @param args Command line arguments
235-
*/
236-
public static void main(String[] args) {
237-
DoublyLinkedList myList = new DoublyLinkedList();
238-
myList.insertHead(13);
239-
myList.insertHead(7);
240-
myList.insertHead(10);
241-
myList.display();
242-
243-
myList.insertTail(11);
244-
myList.display();
245-
246-
myList.deleteTail();
247-
myList.display();
248-
249-
myList.delete(7);
250-
myList.display();
251-
252-
myList.insertOrdered(23);
253-
myList.insertOrdered(67);
254-
myList.insertOrdered(3);
255-
myList.display();
256-
}
257-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.codesquad.datastructurestudy.linkedlist;
2+
3+
public class Link {
4+
/**
5+
* Value of node
6+
*/
7+
public int value;
8+
/**
9+
* This points to the link in front of the new link
10+
*/
11+
public Link next;
12+
/**
13+
* This points to the link behind the new link
14+
*/
15+
public Link previous;
16+
17+
/**
18+
* Constructor
19+
*
20+
* @param value Value of node
21+
*/
22+
public Link(int value) {
23+
this.value = value;
24+
}
25+
26+
/**
27+
* Displays the node
28+
*/
29+
public void displayLink() {
30+
System.out.print(value + " ");
31+
}
32+
33+
/**
34+
* Main Method
35+
*
36+
* @param args Command line arguments
37+
*/
38+
public static void main(String[] args) {
39+
DoublyLinkedList myList = new DoublyLinkedList();
40+
myList.insertHead(13);
41+
myList.insertHead(7);
42+
myList.insertHead(10);
43+
myList.display();
44+
45+
myList.insertTail(11);
46+
myList.display();
47+
48+
myList.deleteTail();
49+
myList.display();
50+
51+
myList.delete(7);
52+
myList.display();
53+
54+
myList.insertOrdered(23);
55+
myList.insertOrdered(67);
56+
myList.insertOrdered(3);
57+
myList.display();
58+
}
59+
}

Diff for: hamill/src/main/java/com/codesquad/datastructurestudy/linkedlist/LinkedList.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class LinkedList {
66
private Node tail;
77
private int size = 0;
88

9-
private static class Node {
9+
public static class Node {
1010
// 데이터가 저장될 필드
1111
private Object data;
1212
// 다음 노드를 가리키는 필드
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.codesquad.datastructurestudy.stack;
2+
3+
public class FixedSizeArrayStack {
4+
protected int capacity;
5+
6+
public static final int CAPACITY = 16;
7+
8+
protected int[] stackArray;
9+
10+
protected int top = -1;
11+
12+
public FixedSizeArrayStack() {
13+
this(CAPACITY);
14+
}
15+
16+
public FixedSizeArrayStack(int cap) {
17+
this.capacity = cap;
18+
this.stackArray = new int[capacity];
19+
}
20+
21+
public int size() {
22+
return (top + 1);
23+
}
24+
25+
public boolean isEmpty() {
26+
return (top < 0);
27+
}
28+
29+
public void push(int data) throws Exception {
30+
if (size() == capacity) {
31+
throw new Exception("Stack is full.");
32+
}
33+
stackArray[++top] = data;
34+
}
35+
36+
public int peek() throws Exception {
37+
if (isEmpty()) {
38+
throw new Exception("Stack is empty");
39+
}
40+
return stackArray[top];
41+
}
42+
43+
public int pop() throws Exception {
44+
int data;
45+
if (isEmpty()) {
46+
throw new Exception("Stack is empty");
47+
}
48+
data = stackArray[top];
49+
stackArray[top--] = Integer.MIN_VALUE;
50+
return data;
51+
}
52+
53+
public static void main(String[] args) throws Exception {
54+
FixedSizeArrayStack myStack = new FixedSizeArrayStack(2);
55+
myStack.push(5);
56+
myStack.push(8);
57+
58+
System.out.println("*********************Fixed Stack Array Implementation*********************");
59+
System.out.println("Size of stack : " + myStack.size());
60+
System.out.println("Pop element from Stack : " + myStack.pop());
61+
System.out.println("Pop element from Stack : " + myStack.pop());
62+
System.out.println("Pop element from Stack : " + myStack.pop());
63+
}
64+
}

0 commit comments

Comments
 (0)