Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- C++
- 자바
- 코딩독학
- 주가예측
- 프로그래머스
- Python
- 백준
- 자바독학
- 프로그램
- 코스닥
- 모의 주식
- 코딩
- frontend
- java
- 프로그래밍
- 코테
- 자바정리
- 풀스택프레임워크
- Project
- 코딩테스트
- java정리
- 이웃한 칸
- 빅데이터
- 개발
- SNS
- Reflex
- 개발자
- 개인프로젝트
- backend
- 사물인터넷
Archives
- Today
- Total
Creative Code
queue3(array클래스와 has -a관계) 본문
※main.cpp파일
#include <iostream>
#include "queue.h"
int main(void)
{
Queue s1(10), s2(100);
s1.push(100);
s1.push(200);
std::cout << "s1 1st pop() : " << s1.pop() << std::endl;
s1.push(300);
std::cout << "s1 2nd pop() : " << s1.pop() << std::endl;
std::cout << "s1 3rd pop() : " << s1.pop() << std::endl;
s2.push(900);
s2.push(800);
std::cout << "s2 1st pop() : " << s2.pop() << std::endl;
s2.push(700);
std::cout << "s2 2nd pop() : " << s2.pop() << std::endl;
std::cout << "s2 3rd pop() : " << s2.pop() << std::endl;
return 0;
}
※queue.h파일
#ifndef QUEUE_H
#define QUEUE_H
#include "array.h"
class Queue {
private:
static const int QUEUESIZE;
Array arr_;
int rear_;
int front_;
Queue(const Queue& rhs);
Queue& operator=(const Queue& rhs);
public:
explicit Queue(int size = Queue::QUEUESIZE);
~Queue();
bool isFull() const;
bool isEmpty() const;
void push(int data);
int pop();
};
#endif
※queue.cpp파일
#include <cstdlib>
#include "queue.h"
#include <cassert>
const int QUEUESIZE = Array::getDefaultSize();
Queue::Queue(int size)
:arr_(size),rear_(0),front_(0)
{
}
Queue::~Queue()
{
}
bool Queue::isFull() const {
return rear_ == arr_.size();
}
bool Queue::isEmpty() const {
return front_ == rear_;
}
void Queue::push(int data)
{
assert(!isFull());
arr_[rear_] = data;
++rear_;
}
int Queue::pop()
{
assert(!isEmpty());
int index = front_;
++front_;
return arr_[index];
}
'C++ Programming' 카테고리의 다른 글
shape(도형 상속) (0) | 2023.09.07 |
---|---|
safeArray2(상속) (0) | 2023.09.07 |
queue2(생성자 초기화 리스트, static member, explicit) (0) | 2023.09.06 |
safeArray(배열 크기) (0) | 2023.09.06 |
stack3(stack,array클래스 연결) (0) | 2023.09.06 |