Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions include/circularQueue/circularQueue.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef circularQueue_HPP
#define circularQueue_HPP

int arr;

class CirQueue {
public:
void enqueue();
void dequeue();
bool isEmpty();
bool isFull();
int size();

};

#endif // circularQueue_HPP
1 change: 1 addition & 0 deletions include/queue/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Queue {
private:
int sp;
int ep;
int count;
Data* buffer;
public:
Queue();
Expand Down
32 changes: 29 additions & 3 deletions include/queue/queue.tpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "queue/queue.hpp"

template<class Data>
Queue<Data>::Queue() : sp(0), ep(0) {
Queue<Data>::Queue() : sp(0), ep(0), count(0) {
buffer = new Data[QUEUE_SIZE];
}

Expand All @@ -14,23 +14,49 @@ template<class Data>
void Queue<Data>::clear() {
sp = 0;
ep = 0;
count = 0;
}



template<class Data>
void Queue<Data>::push(Data data) {
buffer[ep] = data;
//가득차면 돌아와야됨
ep = (ep+1)%QUEUE_SIZE;


if(count == QUEUE_SIZE){
// 가득 찼으면 가장 오래된 원소를 덮어씀
sp = (sp + 1) % QUEUE_SIZE;
}
else{
count++;
}
return;
}

template<class Data>
Data Queue<Data>::pull() {
return buffer[sp];
if (count == 0) {
throw std::invalid_argument("empty queue");
}

Data ret = buffer[sp];
sp = (sp + 1) % QUEUE_SIZE;
count--;
return ret;
}

template<class Data>
Data Queue<Data>::top() {
if (count == 0) {
throw std::invalid_argument("empty queue");
}
return buffer[sp];
}

template<class Data>
int Queue<Data>::size() {
return 0;
return count;
}
4 changes: 0 additions & 4 deletions include/stick/stick.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ class Stick {
void divide2(vector<int>& stick, int idx, int N);
int get_cnt(vector<int> stick);
int ans(vector<int> stick, int N);





};

Expand Down
21 changes: 21 additions & 0 deletions src/circularQueue/circularQueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "circularQueue/circularQueue.hpp"

void CirQueue::enqueue(){

}

void CirQueue::dequeue(){

}

bool CirQueue::isEmpty(){

}

bool CirQueue::isFull(){

}

int CirQueue::size(){

}
4 changes: 4 additions & 0 deletions src/stick/stick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ int Stick::get_cnt(vector<int> stick){
return temp;
}





int Stick::ans(vector<int> stick, int N){
while(sum(stick)!=N){
int idx = find_minidx(stick);
Expand Down
36 changes: 35 additions & 1 deletion test/queue/queue_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,38 @@ TEST_F(QueueTest, push_and_pull) {

// then
EXPECT_EQ(second, v2);
}
}

TEST_F(QueueTest, size){
int v1 = 1;
int v2 = 2;
int_queue.push(v1);
int_queue.push(v2);

EXPECT_EQ(int_queue.size(), 2);

}

TEST_F(QueueTest, push_in_fullqueue) {
for (int i = 0; i < 20; i++) {
int_queue.push(i);
}

int_queue.push(20);
EXPECT_EQ(int_queue.top(), 1);
}

TEST_F(QueueTest, pull_emptyQueue){
EXPECT_THROW(int_queue.pull(), std::invalid_argument);
}

TEST_F(QueueTest, push_getSize){
for(int i=0; i<QUEUE_SIZE; i++){
int_queue.push(i);
}

int_queue.push(4);
int_queue.push(5);

EXPECT_EQ(int_queue.size(), 20);
}