remove data structure folder
This commit is contained in:
parent
7eeac4c949
commit
8a019ee4f5
@ -1,13 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
int numbers[10] = {5, 29, -10, 55, 1, 9, 8, 15, 42, -7};
|
|
||||||
int min = numbers[0], max = numbers[0];
|
|
||||||
for(int i=0; i<10; i++){
|
|
||||||
if(numbers[i]<min) min = numbers[i];
|
|
||||||
if(numbers[i]>max) max = numbers[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("최소값 : %d\n최대값 : %d\n",min, max);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class DS_array {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
ArrayList<Integer> numbers = new ArrayList<>();
|
|
||||||
String[] input = sc.nextLine().split(" ");
|
|
||||||
sc.close();
|
|
||||||
for(String num : input){
|
|
||||||
numbers.add(Integer.parseInt(num));
|
|
||||||
}
|
|
||||||
|
|
||||||
int min = numbers.get(0);
|
|
||||||
int max = numbers.get(0);
|
|
||||||
for(int num : numbers){
|
|
||||||
min = Math.min(min, num);
|
|
||||||
max = Math.max(max, num);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.printf("To. Rino\n최소값 : %d\n최대값 : %d\n..\n",min,max);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
numbers = list(map(int, input().split()))
|
|
||||||
min_value = max_value = numbers[0]
|
|
||||||
|
|
||||||
for num in numbers:
|
|
||||||
min_value = num if num < min_value else min_value
|
|
||||||
max_value = num if num > max_value else max_value
|
|
||||||
|
|
||||||
result = "\n최소값: " + str(min_value) + "\n최대값: " + str(max_value) + "\n"
|
|
||||||
print(result)
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
if let input = readLine(),
|
|
||||||
let numbers = {
|
|
||||||
let tempNumbers = input.split(separator: " ").compactMap({Int($0)})
|
|
||||||
return tempNumbers.isEmpty ? nil : tempNumbers
|
|
||||||
}() {
|
|
||||||
|
|
||||||
var min = numbers[0]
|
|
||||||
var max = numbers[0]
|
|
||||||
|
|
||||||
for num in numbers {
|
|
||||||
min = min > num ? num : min
|
|
||||||
max = max < num ? num : max
|
|
||||||
}
|
|
||||||
|
|
||||||
print("\n최소값 : \(min)\n최대값 : \(max)\n")
|
|
||||||
|
|
||||||
} else {
|
|
||||||
print("error")
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
const numbers: number[] = require("fs").readFileSync(0, "utf8").toString().split(' ').map(Number);
|
|
||||||
let [min, max]: number[] = [numbers[0], numbers[0]]
|
|
||||||
|
|
||||||
for(let num of numbers){
|
|
||||||
min = min > num ? num : min;
|
|
||||||
max = max < num ? num : max;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(min, max);
|
|
||||||
@ -1,156 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
typedef struct C_Queue C_Queue;
|
|
||||||
|
|
||||||
void _enqueue(C_Queue *q, int value);
|
|
||||||
int _dequeue(C_Queue *q);
|
|
||||||
bool _isEmpty(C_Queue *q);
|
|
||||||
bool _isFull(C_Queue *q);
|
|
||||||
void _info(C_Queue *q);
|
|
||||||
void _destroyQ(C_Queue *q);
|
|
||||||
|
|
||||||
struct C_Queue{
|
|
||||||
int *data;
|
|
||||||
int front, rear, size;
|
|
||||||
|
|
||||||
bool (*isEmpty)(C_Queue *q);
|
|
||||||
bool (*isFull)(C_Queue *q);
|
|
||||||
void (*enqueue)(C_Queue *q, int value);
|
|
||||||
int (*dequeue)(C_Queue *q);
|
|
||||||
void (*info)(C_Queue *q);
|
|
||||||
void (*destroyQ)(C_Queue *q);
|
|
||||||
};
|
|
||||||
|
|
||||||
C_Queue creatQueue(int capacity){
|
|
||||||
C_Queue q;
|
|
||||||
q.front = -1;
|
|
||||||
q.rear = -1;
|
|
||||||
q.size = capacity;
|
|
||||||
q.data = (int*)malloc(sizeof(int)*capacity);
|
|
||||||
|
|
||||||
q.enqueue = _enqueue;
|
|
||||||
q.dequeue = _dequeue;
|
|
||||||
q.info = _info;
|
|
||||||
q.isEmpty = _isEmpty;
|
|
||||||
q.isFull = _isFull;
|
|
||||||
q.destroyQ = _destroyQ;
|
|
||||||
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
|
|
||||||
int opcode(char *input);
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
printf("생성하려는 원형큐의 용량을 입력해주세요. : ");
|
|
||||||
int capacity;
|
|
||||||
scanf("%d",&capacity);
|
|
||||||
|
|
||||||
C_Queue q = creatQueue(capacity);
|
|
||||||
bool exit_flag = true;
|
|
||||||
while(exit_flag){
|
|
||||||
printf("+++++++++++++++++++++++++++++++++++++++++++++++++\n");
|
|
||||||
printf("명령어 목록 : enqueue | dequeue | info | exit\n");
|
|
||||||
printf("명령어를 입력해주세요. : ");
|
|
||||||
char input[10];
|
|
||||||
scanf("%s",input);
|
|
||||||
switch (opcode(input))
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
if(q.isFull(&q)) {
|
|
||||||
printf("큐가 꽉차있어서 입력할 수 없습니다.\n");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
printf("넣을 값을 입력해주세요. : ");
|
|
||||||
int num;
|
|
||||||
scanf("%d",&num);
|
|
||||||
q.enqueue(&q, num);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if(q.isEmpty(&q)){
|
|
||||||
printf("큐가 비어있어서 값을 꺼낼 수가 없습니다.\n");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
printf("추출값 : %d\n",q.dequeue(&q));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
q.info(&q);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
exit_flag = false;
|
|
||||||
printf("종료합니다\n");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("명령어를 잘못 입력했습니다. 다시 입력해주세요.\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
q.destroyQ(&q);
|
|
||||||
}
|
|
||||||
|
|
||||||
int opcode(char *input){
|
|
||||||
if(!strcmp(input, "enqueue")) return 1;
|
|
||||||
if(!strcmp(input, "dequeue")) return 2;
|
|
||||||
if(!strcmp(input, "info")) return 3;
|
|
||||||
if(!strcmp(input, "exit")) return 4;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _isEmpty(C_Queue *q){
|
|
||||||
return q->front == -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _isFull(C_Queue *q){
|
|
||||||
return ((q->rear)+1)%(q->size) == q->front;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _enqueue(C_Queue *q, int value){
|
|
||||||
if(q->isFull(q)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(q->isEmpty(q)){
|
|
||||||
q->front = 0;
|
|
||||||
}
|
|
||||||
q->rear = ((q->rear)+1)%(q->size);
|
|
||||||
q->data[q->rear] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
int _dequeue(C_Queue *q){
|
|
||||||
if(q->isEmpty(q)){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
int value = q->data[q->front];
|
|
||||||
if(q->front == q->rear){
|
|
||||||
q->front = -1;
|
|
||||||
q->rear = -1;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
q->front = ((q->front)+1)%q->size;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _info(C_Queue *q){
|
|
||||||
if(q->isEmpty(q)){
|
|
||||||
printf("큐가 비어있습니다.\n");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
printf("큐 목록: ");
|
|
||||||
int i = q->front;
|
|
||||||
while(true){
|
|
||||||
printf("%d ",q->data[i]);
|
|
||||||
if(i==q->rear) break;
|
|
||||||
i = (i+1)%q->size;
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _destroyQ(C_Queue *q){
|
|
||||||
free(q->data);
|
|
||||||
}
|
|
||||||
@ -1,120 +0,0 @@
|
|||||||
import java.security.cert.TrustAnchor;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
class Cir_Queue {
|
|
||||||
private int[] data;
|
|
||||||
private int front, rear, size;
|
|
||||||
|
|
||||||
Cir_Queue(int size){
|
|
||||||
this.data = new int[size];
|
|
||||||
this.front = -1;
|
|
||||||
this.rear = -1;
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty(){
|
|
||||||
return this.front == -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFull(){
|
|
||||||
return (this.rear + 1)%(this.size) == front;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enqueue(int value){
|
|
||||||
if(this.isFull()){
|
|
||||||
System.out.println("Queue is Full!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(this.isEmpty()){
|
|
||||||
this.front = 0;
|
|
||||||
}
|
|
||||||
this.rear = (this.rear + 1)%(this.size);
|
|
||||||
this.data[rear] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int dequeue(){
|
|
||||||
if(this.isEmpty()){
|
|
||||||
System.out.println("Queue is Empty!");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
int value = this.data[this.front];
|
|
||||||
if(this.rear == this.front){
|
|
||||||
this.rear = -1;
|
|
||||||
this.front = -1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.front = (this.front + 1)%this.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int peek(){
|
|
||||||
if(this.isEmpty()){
|
|
||||||
System.out.println("Queue is Empty!");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return this.data[this.front];
|
|
||||||
}
|
|
||||||
|
|
||||||
public void info(){
|
|
||||||
if(this.isEmpty()){
|
|
||||||
System.out.println("큐가 비어있습니다.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder("Queue List : ");
|
|
||||||
int i = this.front;
|
|
||||||
while(true){
|
|
||||||
result.append(this.data[i] + " ");
|
|
||||||
if(i==this.rear) break;
|
|
||||||
i = (i + 1)%this.size;
|
|
||||||
}
|
|
||||||
System.out.println(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DS_queue {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Scanner sc= new Scanner(System.in);
|
|
||||||
System.out.println("큐의 사이즈를 입력해주세요.");
|
|
||||||
int size = Integer.parseInt(sc.nextLine());
|
|
||||||
Cir_Queue q = new Cir_Queue(size);
|
|
||||||
|
|
||||||
boolean exitFlag = true;
|
|
||||||
while(exitFlag){
|
|
||||||
System.out.println("명령어 목록 : enque [value] | deque | peek | info | exit");
|
|
||||||
String[] opcode = sc.nextLine().split(" ");
|
|
||||||
switch (opcode[0]) {
|
|
||||||
case "enque":
|
|
||||||
q.enqueue(Integer.parseInt(opcode[1]));
|
|
||||||
break;
|
|
||||||
case "deque":
|
|
||||||
if(q.isEmpty()){
|
|
||||||
q.dequeue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
System.out.println(q.dequeue());
|
|
||||||
break;
|
|
||||||
case "peek":
|
|
||||||
if(q.isEmpty()){
|
|
||||||
q.peek();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
System.out.println(q.peek());
|
|
||||||
break;
|
|
||||||
case "info":
|
|
||||||
q.info();
|
|
||||||
break;
|
|
||||||
case "exit":
|
|
||||||
exitFlag = false;
|
|
||||||
System.out.println("Exit!!");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
System.out.println("제대로 입력해주세요.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sc.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,96 +0,0 @@
|
|||||||
class queue :
|
|
||||||
|
|
||||||
def __init__(self,size) :
|
|
||||||
self.__size = size
|
|
||||||
self.__data = [0]*size
|
|
||||||
self.__front = -1
|
|
||||||
self.__rear = -1
|
|
||||||
|
|
||||||
def isEmpty(self) :
|
|
||||||
return self.__front == -1
|
|
||||||
|
|
||||||
def isFull(self) :
|
|
||||||
return (self.__rear + 1)%(self.__size) == self.__front
|
|
||||||
|
|
||||||
def enqueue(self, value) :
|
|
||||||
if self.isFull() :
|
|
||||||
print("Queue is Full!!")
|
|
||||||
return
|
|
||||||
|
|
||||||
if self.isEmpty() :
|
|
||||||
self.__front = 0
|
|
||||||
|
|
||||||
self.__rear = (self.__rear + 1) % self.__size
|
|
||||||
self.__data[self.__rear] = value
|
|
||||||
print("삽입 완료")
|
|
||||||
|
|
||||||
def dequeue(self) :
|
|
||||||
if self.isEmpty() :
|
|
||||||
print("Queue is Empty!")
|
|
||||||
return -1
|
|
||||||
|
|
||||||
value = self.__data[self.__front]
|
|
||||||
|
|
||||||
if self.__front == self.__rear :
|
|
||||||
self.__front = -1
|
|
||||||
self.__rear = -1
|
|
||||||
else :
|
|
||||||
self.__front = (self.__front + 1) % self.__size
|
|
||||||
|
|
||||||
print(value)
|
|
||||||
|
|
||||||
return value
|
|
||||||
|
|
||||||
def peek(self) :
|
|
||||||
if self.isEmpty() :
|
|
||||||
print("Queue is Empty!")
|
|
||||||
return -1
|
|
||||||
|
|
||||||
value = self.__data[self.__front]
|
|
||||||
|
|
||||||
print(value)
|
|
||||||
|
|
||||||
return value
|
|
||||||
|
|
||||||
def info(self) :
|
|
||||||
if self.isEmpty() :
|
|
||||||
print("Queue is Empty!, Max Size is : {0}".format(self.__size))
|
|
||||||
return
|
|
||||||
|
|
||||||
i = self.__front
|
|
||||||
result = "Queue List : [ "
|
|
||||||
while True:
|
|
||||||
result += str(self.__data[i])
|
|
||||||
if i == self.__rear :
|
|
||||||
result += " ]"
|
|
||||||
break
|
|
||||||
|
|
||||||
result += ", "
|
|
||||||
i = (i + 1) % self.__size
|
|
||||||
|
|
||||||
print("Max Size is : {0}".format(self.__size))
|
|
||||||
print(result)
|
|
||||||
|
|
||||||
q = queue(int(input("원형큐의 최대사이즈를 입력해주세요 : ")))
|
|
||||||
|
|
||||||
endFlag = True
|
|
||||||
|
|
||||||
while endFlag :
|
|
||||||
opcode = input("명령어 목록 : enqueue [num] | dequeue | peek | info | exit\n")
|
|
||||||
|
|
||||||
if "enqueue" in opcode :
|
|
||||||
if opcode.split()[0] != "enqueue" :
|
|
||||||
print("제대로 입력해주세요 enqueue와 정수를 입력받습니다.")
|
|
||||||
continue
|
|
||||||
q.enqueue(int(opcode.split()[1]))
|
|
||||||
elif opcode == "dequeue" :
|
|
||||||
q.dequeue()
|
|
||||||
elif opcode == "peek" :
|
|
||||||
q.peek()
|
|
||||||
elif opcode == "info" :
|
|
||||||
q.info()
|
|
||||||
elif opcode == "exit" :
|
|
||||||
endFlag = False
|
|
||||||
print("Exit")
|
|
||||||
else :
|
|
||||||
print("제대로 입력해주세요")
|
|
||||||
@ -1,117 +0,0 @@
|
|||||||
class CircularQueue {
|
|
||||||
private var data: [Int]
|
|
||||||
private var front, rear, size : Int
|
|
||||||
|
|
||||||
init(size: Int){
|
|
||||||
self.front = -1
|
|
||||||
self.rear = -1
|
|
||||||
self.size = size
|
|
||||||
self.data = Array(repeating: 0, count: size)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isEmpty() -> Bool {
|
|
||||||
return self.front == -1
|
|
||||||
}
|
|
||||||
|
|
||||||
func isFull() -> Bool {
|
|
||||||
return (self.rear + 1)%self.size == self.front
|
|
||||||
}
|
|
||||||
|
|
||||||
func info(){
|
|
||||||
if self.isEmpty(){
|
|
||||||
print("Empty!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var i: Int = self.front
|
|
||||||
while true {
|
|
||||||
print("\(self.data[i]) ",terminator: " ")
|
|
||||||
if i == self.rear {
|
|
||||||
print()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
i = (i+1)%self.size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func enqueue(to value: Int){
|
|
||||||
if self.isFull() {
|
|
||||||
print("Full!!!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.isEmpty(){
|
|
||||||
self.front = 0
|
|
||||||
}
|
|
||||||
self.rear = (self.rear + 1)%self.size
|
|
||||||
self.data[self.rear] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
func dequeue() -> Int? {
|
|
||||||
if self.isEmpty(){
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
let value: Int = self.data[self.front]
|
|
||||||
if(self.front == self.rear){
|
|
||||||
self.front = -1
|
|
||||||
self.rear = -1
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.front = (self.front+1) % self.size
|
|
||||||
}
|
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
func peek() -> Int? {
|
|
||||||
if self.isEmpty(){
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return self.data[self.front]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let cirQueue: CircularQueue = CircularQueue(size: 10)
|
|
||||||
var exitFlag: Bool = true
|
|
||||||
|
|
||||||
while exitFlag {
|
|
||||||
print("명령어를 입력하세요 (enqueue [값], dequeue, peek, info, exit):")
|
|
||||||
if let input = readLine() {
|
|
||||||
let components = input.split(separator: " ")
|
|
||||||
let order = String(components.first ?? "")
|
|
||||||
|
|
||||||
switch order {
|
|
||||||
case "enqueue" :
|
|
||||||
if components.count == 2, let value = Int(components[1]) {
|
|
||||||
cirQueue.enqueue(to: value)
|
|
||||||
print("\(value) enqueue!")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
print("enqueue 명령어 뒤에 공백에 이어서 숫자를 입력해야합니다.")
|
|
||||||
}
|
|
||||||
case "dequeue" :
|
|
||||||
if let value = cirQueue.dequeue(){
|
|
||||||
print("\(value) dequeue!!")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
print("Empty!!")
|
|
||||||
}
|
|
||||||
case "peek" :
|
|
||||||
if let value = cirQueue.peek(){
|
|
||||||
print("\(value) peek!!")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
print("Empty!!")
|
|
||||||
}
|
|
||||||
case "info" :
|
|
||||||
cirQueue.info()
|
|
||||||
case "exit" :
|
|
||||||
exitFlag = false
|
|
||||||
print("Exit!!!")
|
|
||||||
default :
|
|
||||||
print("제대로 된 명령어를 입력하세요")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
print("제대로 입력해주세요")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,109 +0,0 @@
|
|||||||
export {};
|
|
||||||
|
|
||||||
class CircularQueue {
|
|
||||||
private data: number[];
|
|
||||||
private front: number;
|
|
||||||
private rear: number
|
|
||||||
private size: number;
|
|
||||||
|
|
||||||
constructor(size: number){
|
|
||||||
this.size = size;
|
|
||||||
this.rear = -1;
|
|
||||||
this.front = -1;
|
|
||||||
this.data = Array.from({length: size}, () => 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public isEmpty(): boolean{
|
|
||||||
return this.front === -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public isFull(): boolean{
|
|
||||||
return (this.rear + 1)%(this.size) === this.front;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enqueue(value: number){
|
|
||||||
if(this.isFull()){
|
|
||||||
console.log("Queue is full!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(this.isEmpty()){
|
|
||||||
this.front = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.rear = (this.rear + 1)%(this.size);
|
|
||||||
this.data[this.rear] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public dequeue(): number | undefined {
|
|
||||||
if(this.isEmpty()) return undefined;
|
|
||||||
const value: number = this.data[this.front];
|
|
||||||
if(this.rear === this.front) {
|
|
||||||
this.rear = -1;
|
|
||||||
this.front = -1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.front = (this.front + 1)%(this.size);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public peek(): number | undefined {
|
|
||||||
return (this.isEmpty()) ? undefined : this.data[this.front];
|
|
||||||
}
|
|
||||||
|
|
||||||
public info() {
|
|
||||||
if(this.isEmpty()){
|
|
||||||
console.log("Empty!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let result = "list : [";
|
|
||||||
let i = this.front;
|
|
||||||
while(true){
|
|
||||||
result += this.data[i].toString();
|
|
||||||
if(i === this.rear){
|
|
||||||
result += "]";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i = (i+1)%(this.size);
|
|
||||||
result += ",";
|
|
||||||
}
|
|
||||||
console.log(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("원형큐를 생성합니다. 사이즈를 입력해주세요.")
|
|
||||||
const size: number = Number(require("fs").readFileSync(0,"utf8").toString().trim());
|
|
||||||
let cq = new CircularQueue(size);
|
|
||||||
let exitFlag: boolean = true;
|
|
||||||
|
|
||||||
while(exitFlag){
|
|
||||||
console.log("++++++++++++++++명령어모음++++++++++++++++");
|
|
||||||
console.log("enqueue <value> | dequeue | peek | info | exit");
|
|
||||||
console.log("========================================");
|
|
||||||
console.log("명령어를 입력해주세요!");
|
|
||||||
const input:string[] = require("fs").readFileSync(0,"utf8").toString().trim().split(" ");
|
|
||||||
switch(input[0])
|
|
||||||
{
|
|
||||||
case "enqueue":
|
|
||||||
cq.enqueue(Number(input[1]));
|
|
||||||
break;
|
|
||||||
case "dequeue":
|
|
||||||
const deqvalue = cq.dequeue();
|
|
||||||
console.log(deqvalue===undefined ? "큐가 비었습니다." : deqvalue);
|
|
||||||
break;
|
|
||||||
case "peek":
|
|
||||||
const peekValue = cq.peek();
|
|
||||||
console.log(peekValue===undefined ? "큐가 비었습니다." : peekValue);
|
|
||||||
break;
|
|
||||||
case "info":
|
|
||||||
cq.info();
|
|
||||||
break;
|
|
||||||
case "exit":
|
|
||||||
exitFlag = false;
|
|
||||||
console.log("종료합니다.")
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.log("제대로 입력해주세요.")
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,83 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define MAX_SIZE 100
|
|
||||||
|
|
||||||
typedef struct Stack Stack;
|
|
||||||
|
|
||||||
struct Stack {
|
|
||||||
int data[MAX_SIZE];
|
|
||||||
int top;
|
|
||||||
|
|
||||||
void (*push)(Stack *s, int value);
|
|
||||||
int (*pop)(Stack *s);
|
|
||||||
bool (*isEmpty)(Stack *s);
|
|
||||||
};
|
|
||||||
|
|
||||||
void _push(Stack *s, int value){
|
|
||||||
if(s->top == MAX_SIZE-1){
|
|
||||||
printf("Stack is full!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
s->data[++(s->top)] = value;
|
|
||||||
printf("stack : ");
|
|
||||||
for(int i=0; i<=s->top; i++){
|
|
||||||
printf("%d ",s->data[i]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
int _pop(Stack *s){
|
|
||||||
if(s->top == -1){
|
|
||||||
printf("Stack is empty ");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return s->data[(s->top)--];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _isEmpty(Stack *s){
|
|
||||||
return s->top == -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Stack creatStack(){
|
|
||||||
Stack s;
|
|
||||||
s.top = -1;
|
|
||||||
s.push = _push;
|
|
||||||
s.pop = _pop;
|
|
||||||
s.isEmpty = _isEmpty;
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
Stack stack = creatStack();
|
|
||||||
while(true){
|
|
||||||
char input[10];
|
|
||||||
|
|
||||||
printf("\n명령을 입력하세요 (push, pop, isEmpty, exit): ");
|
|
||||||
scanf("%s", input);
|
|
||||||
|
|
||||||
if(!strcmp(input, "push")){
|
|
||||||
int value;
|
|
||||||
printf("스택에 넣을 값을 입력해주세요 : ");
|
|
||||||
scanf("%d", &value);
|
|
||||||
stack.push(&stack, value);
|
|
||||||
}
|
|
||||||
else if(!strcmp(input, "pop")){
|
|
||||||
int poppedValue = stack.pop(&stack);
|
|
||||||
|
|
||||||
if(poppedValue != -1){
|
|
||||||
printf("Pop value : %d\n", poppedValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(!strcmp(input, "isEmpty")){
|
|
||||||
printf("%s\n", stack.isEmpty(&stack) ? "스택이 비었습니다" : "스택이 비어있지 않습니다.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("종료합니다\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@ -1,94 +0,0 @@
|
|||||||
import java.util.*;
|
|
||||||
|
|
||||||
class Stack{
|
|
||||||
private int[] data;
|
|
||||||
private int top;
|
|
||||||
private int maxSize;
|
|
||||||
|
|
||||||
Stack(int maxSize){
|
|
||||||
data = new int[maxSize];
|
|
||||||
top = -1;
|
|
||||||
this.maxSize = maxSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
void stackInfo(){
|
|
||||||
if(top == -1){
|
|
||||||
System.out.println("현재 스택 목록 : Empty!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
System.out.printf("현재 스택 목록 : ");
|
|
||||||
for(int i=0; i<=top; i++) {
|
|
||||||
System.out.printf("%d ",this.data[i]);
|
|
||||||
}
|
|
||||||
System.out.printf("\ntop : %d\n",this.top);
|
|
||||||
}
|
|
||||||
|
|
||||||
void push(int value){
|
|
||||||
if(top == maxSize - 1){
|
|
||||||
System.out.println("스택이 꽉찼기 때문에 추가할 수 없습니다.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.data[++(this.top)] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void pop(){
|
|
||||||
if(this.top == -1){
|
|
||||||
System.out.println("스택이 비어있어서 처리할 수 없습니다.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
System.out.printf("빠져나온 데이터 : %d\n",this.data[(this.top)--]);
|
|
||||||
}
|
|
||||||
|
|
||||||
int peek(){
|
|
||||||
return this.data[top];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DS_stack {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Scanner Order = new Scanner(System.in);
|
|
||||||
System.out.printf("스택의 최대길이를 입력해주세요. : ");
|
|
||||||
int maxSize = Integer.parseInt(Order.nextLine());
|
|
||||||
Stack stack = new Stack(maxSize);
|
|
||||||
boolean exit = false;
|
|
||||||
|
|
||||||
while(!exit){
|
|
||||||
System.out.println("======명령어 목록======");
|
|
||||||
System.out.println("1. push <value>");
|
|
||||||
System.out.println("2. pop");
|
|
||||||
System.out.println("3. peek");
|
|
||||||
System.out.println("4. info");
|
|
||||||
System.out.println("5. exit");
|
|
||||||
System.out.println("=====================");
|
|
||||||
System.out.printf("명령어를 입력하세요 : ");
|
|
||||||
String[] order = Order.nextLine().split(" ");
|
|
||||||
if (order[0] != null){
|
|
||||||
switch (order[0]){
|
|
||||||
case "push":
|
|
||||||
stack.push(Integer.parseInt(order[1]));
|
|
||||||
break;
|
|
||||||
case "pop":
|
|
||||||
stack.pop();
|
|
||||||
break;
|
|
||||||
case "peek":
|
|
||||||
System.out.printf("최상단 값 : %d\n",stack.peek());
|
|
||||||
break;
|
|
||||||
case "info":
|
|
||||||
stack.stackInfo();
|
|
||||||
break;
|
|
||||||
case "exit":
|
|
||||||
exit = true;
|
|
||||||
System.out.println("종료합니다!");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
System.out.println("제대로 입력해주세요.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
System.out.println("명령어 목록을 잘 확인해서 다시 입력해주세요.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Order.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,64 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
input = sys.stdin.readline
|
|
||||||
|
|
||||||
class Stack:
|
|
||||||
def __init__(self, maxSize):
|
|
||||||
self.__size = maxSize
|
|
||||||
self.__data = [0]*maxSize
|
|
||||||
self.__top = -1
|
|
||||||
|
|
||||||
def stackInfo(self):
|
|
||||||
if self.__top == -1 :
|
|
||||||
print("Stack is Empty")
|
|
||||||
return
|
|
||||||
|
|
||||||
print("====현재 스택목록({}/{})====".format(self.__top+1,self.__size))
|
|
||||||
for i in range(self.__top+1):
|
|
||||||
print(self.__data[i], end = " ")
|
|
||||||
print()
|
|
||||||
|
|
||||||
def push(self, value):
|
|
||||||
if self.__top == self.__size - 1 :
|
|
||||||
print("스택이 꽉찼기 때문에 동작을 수행할 수 없습니다.")
|
|
||||||
return
|
|
||||||
self.__top += 1
|
|
||||||
self.__data[self.__top] = value
|
|
||||||
print("push 완료")
|
|
||||||
|
|
||||||
def pop(self):
|
|
||||||
if self.__top == -1 :
|
|
||||||
print("스택이 비어있어서 pop할 값이 없습니다")
|
|
||||||
return
|
|
||||||
print(self.__data[self.__top])
|
|
||||||
self.__top -= 1
|
|
||||||
|
|
||||||
def peek(self):
|
|
||||||
if self.__top == -1 :
|
|
||||||
print("스택이 비어있어서 최상단 값이 없습니다")
|
|
||||||
return
|
|
||||||
print(self.__data[self.__top])
|
|
||||||
|
|
||||||
print("스택의 최대사이즈를 입력해줘!")
|
|
||||||
stack = Stack(int(input()))
|
|
||||||
|
|
||||||
endPoint = False
|
|
||||||
|
|
||||||
while not endPoint :
|
|
||||||
print("명령어 목록")
|
|
||||||
print("push <value> | pop | info | peek | exit")
|
|
||||||
order = input().split()
|
|
||||||
match order[0]:
|
|
||||||
case "push":
|
|
||||||
stack.push(int(order[1]))
|
|
||||||
case "pop":
|
|
||||||
stack.pop()
|
|
||||||
case "info":
|
|
||||||
stack.stackInfo()
|
|
||||||
case "peek":
|
|
||||||
stack.peek()
|
|
||||||
case "exit":
|
|
||||||
print("종료")
|
|
||||||
endPoint = True
|
|
||||||
case _:
|
|
||||||
print("제대로 된 명령어를 입력해주세요.")
|
|
||||||
@ -1,99 +0,0 @@
|
|||||||
class Stack {
|
|
||||||
private var data: [Int]
|
|
||||||
private let maxSize: Int
|
|
||||||
private var top: Int
|
|
||||||
|
|
||||||
init(size: Int) {
|
|
||||||
self.maxSize = size
|
|
||||||
self.data = Array(repeating: 0, count: size)
|
|
||||||
self.top = -1
|
|
||||||
}
|
|
||||||
|
|
||||||
func isFull() -> Bool {
|
|
||||||
return self.top == self.maxSize - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
func isEmpty() -> Bool {
|
|
||||||
return self.top == -1
|
|
||||||
}
|
|
||||||
|
|
||||||
func push(to value: Int) {
|
|
||||||
if isFull() {
|
|
||||||
print("스택 오버플로우! 더 이상 추가할 수 없습니다.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
self.top += 1
|
|
||||||
self.data[top] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
func pop() -> Int? {
|
|
||||||
if isEmpty() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
let popValue = self.data[top]
|
|
||||||
self.top -= 1
|
|
||||||
return popValue
|
|
||||||
}
|
|
||||||
|
|
||||||
func peek() -> Int? {
|
|
||||||
if isEmpty() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return self.data[top]
|
|
||||||
}
|
|
||||||
|
|
||||||
func info(){
|
|
||||||
if isEmpty() {
|
|
||||||
print("스택이 비어있습니다.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
print("스택목록 : ", terminator: "")
|
|
||||||
for i in 0...self.top {
|
|
||||||
print(self.data[i], terminator: " ")
|
|
||||||
}
|
|
||||||
print()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let stack: Stack = Stack(size: 10)
|
|
||||||
var exitFlag = true
|
|
||||||
|
|
||||||
while exitFlag {
|
|
||||||
print("명령어를 입력하세요 (push [값], pop, peek, info, exit):")
|
|
||||||
if let input = readLine(){
|
|
||||||
let components = input.split(separator: " ")
|
|
||||||
let order = String(components.first ?? "")
|
|
||||||
|
|
||||||
switch order {
|
|
||||||
case "push":
|
|
||||||
if components.count == 2, let value = Int(components[1]) {
|
|
||||||
stack.push(to: value)
|
|
||||||
print("\(value)를 push했습니다.")
|
|
||||||
} else {
|
|
||||||
print("push 명령어는 'push [숫자]' 형식으로 입력해야 합니다.")
|
|
||||||
}
|
|
||||||
case "pop":
|
|
||||||
if let popValue = stack.pop() {
|
|
||||||
print("Pop: \(popValue)")
|
|
||||||
} else {
|
|
||||||
print("스택이 비어있습니다.")
|
|
||||||
}
|
|
||||||
case "peek":
|
|
||||||
if let peekValue = stack.peek() {
|
|
||||||
print("Peek: \(peekValue)")
|
|
||||||
} else {
|
|
||||||
print("스택이 비어있습니다.")
|
|
||||||
}
|
|
||||||
case "info":
|
|
||||||
stack.info()
|
|
||||||
case "exit":
|
|
||||||
exitFlag = false
|
|
||||||
print("종료합니다")
|
|
||||||
default:
|
|
||||||
print("알 수 없는 명령어입니다.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
print("제대로 입력해주세요")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,77 +0,0 @@
|
|||||||
class Stack{
|
|
||||||
private data: number[];
|
|
||||||
private top: number;
|
|
||||||
|
|
||||||
constructor(){
|
|
||||||
this.data = [];
|
|
||||||
this.top = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public info(){
|
|
||||||
if(this.top == -1){
|
|
||||||
console.log("스택이 비어있습니다");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let result: string = "Stack List(" + (this.top+1).toString() + " values) : "
|
|
||||||
for(let i=0; i<=this.top; i++){
|
|
||||||
result += this.data[i].toString() + " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public push(value: number){
|
|
||||||
this.data[++(this.top)] = value;
|
|
||||||
console.log("push 성공!");
|
|
||||||
}
|
|
||||||
|
|
||||||
public pop(): number | undefined {
|
|
||||||
if(this.top === -1){
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return this.data[(this.top)--];
|
|
||||||
}
|
|
||||||
|
|
||||||
public peek(): number | undefined {
|
|
||||||
if(this.top === -1){
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return this.data[this.top];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let stack = new Stack();
|
|
||||||
let exitFlag = true;
|
|
||||||
|
|
||||||
while(exitFlag){
|
|
||||||
console.log("++++++++++++++++명령어모음++++++++++++++++");
|
|
||||||
console.log("push <value> | pop | peek | info | exit");
|
|
||||||
console.log("========================================");
|
|
||||||
console.log("명령어를 입력해주세요!");
|
|
||||||
const input:string[] = require("fs").readFileSync(0,"utf8").toString().trim().split(" ");
|
|
||||||
switch(input[0])
|
|
||||||
{
|
|
||||||
case "push":
|
|
||||||
stack.push(Number(input[1]));
|
|
||||||
break;
|
|
||||||
case "pop":
|
|
||||||
var popValue = stack.pop();
|
|
||||||
console.log(popValue===undefined ? "스택이 비었습니다." : "pop 완료 : " + popValue.toString());
|
|
||||||
break;
|
|
||||||
case "peek":
|
|
||||||
var peekValue = stack.peek();
|
|
||||||
console.log(peekValue===undefined ? "스택이 비었습니다." : "최상단 값 : " + peekValue.toString());
|
|
||||||
break;
|
|
||||||
case "info":
|
|
||||||
stack.info();
|
|
||||||
break;
|
|
||||||
case "exit":
|
|
||||||
exitFlag = false;
|
|
||||||
console.log("종료합니다.")
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.log("제대로 입력해주세요.")
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user