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
- Python
- 코스닥
- frontend
- C++
- 코딩
- SNS
- 자바정리
- 프로그래밍
- 자바
- Reflex
- 개발자
- 백준
- 빅데이터
- 코딩테스트
- backend
- 개발
- 주가예측
- java정리
- 이웃한 칸
- 개인프로젝트
- 코딩독학
- 코테
- 풀스택프레임워크
- Project
- 자바독학
- 프로그램
- 사물인터넷
- 모의 주식
- 프로그래머스
- java
Archives
- Today
- Total
Creative Code
main.cpp(queue) 본문
※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
class Queue {
private:
int *array;
int rear;
int front;
int size;
public:
Queue(int size);
~Queue();
void push(int data);
int pop();
};
#endif
※queue.cpp파일
#include <cstdlib>
#include "queue.h"
Queue::Queue(int size)
{
this->array = new int[size];
this->size = size;
this->rear = 0;
this->front = 0;
}
Queue::~Queue()
{
delete[] this->array;
}
void Queue::push(int data)
{
this->array[this->rear] = data;
++this->rear;
}
int Queue::pop()
{
int index = this->front;
++this->front;
return this->array[index];
}
'C++ Programming' 카테고리의 다른 글
main.cpp(Rational 사칙연산) (0) | 2023.08.30 |
---|---|
main.cpp(complex 연산) (0) | 2023.08.30 |
main.cpp(complex 클래스) (0) | 2023.08.30 |
main.cpp(linked list) (0) | 2023.08.29 |
main.cpp(스택) (0) | 2023.08.29 |