Skip to content

Commit

Permalink
[Stack] Fix Stack
Browse files Browse the repository at this point in the history
  • Loading branch information
deunlee committed May 24, 2020
1 parent bbec51c commit be9cdfa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions Stack/Stack.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#include "Stack.h"

namespace Deun {
Stack::Stack(unsigned long size) {
Stack::Stack(unsigned int size) {
this->size = size;
top = 0;
elements = new (std::nothrow) int[size];

if (!elements) {
this->size = 0;
throw StackError::STACK_ALLOCATE_FAILED;
throw StackError::STACK_ALLOCATION_FAILED;
}
}

Stack::~Stack() {
delete[] elements;
}

bool Stack::isFull() {
return (top == size);
}

bool Stack::isEmpty() {
return (top == 0);
}

unsigned long Stack::getSize() {
bool Stack::isFull() {
return (top == size);
}

unsigned int Stack::getSize() {
return size;
}

unsigned long Stack::getCount() {
unsigned int Stack::getCount() {
return top;
}

Expand Down
18 changes: 9 additions & 9 deletions Stack/Stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@

namespace Deun {
enum class StackError {
STACK_ALLOCATE_FAILED,
STACK_IS_FULL,
STACK_ALLOCATION_FAILED,
STACK_IS_EMPTY,
};

// 배열 기반 스택
class Stack {
private:
int* elements;
unsigned long size;
unsigned long top;
unsigned int size;
unsigned int top;

public:
Stack(unsigned long size = 100);
Stack(unsigned int size = 100);
~Stack();

bool isFull();
bool isEmpty();

unsigned long getSize();
unsigned long getCount();
bool isFull();

unsigned int getSize();
unsigned int getCount();

bool push(int element);
int pop();
Expand Down

0 comments on commit be9cdfa

Please sign in to comment.