c++ stack 구현

공부하러왔어요의 이미지

c++에서 첨부파일 문제를 풀다가 모르겠어서 질문합니다 고수분들 알려주시면 감사하겠습니다ㅠ

1) 스택을 직접 정의하고 구현하여야 합니다.
(스택 STL을 사용하면 안됩니다.)

스택의 배열 구현에서 배열 크기는 30이상으로 하시바랍니다.

2) 강의 자료 스택의 구현에서 error 함수의 매개변수는 다음과 같이 const로 변경하기 바랍니다.

inline void error(const char *message) {
cout << message << endl;
exit(1);
}

3) goorm 사이트에 제출하는 여러분의 프로그램은 표준입력(cin.get 함수 이용)을 사용하여야 합니다.

i) 여러분이 작성한 프로그램의 테스팅은 화면입력보다는 파일입력으로 테스트하는 것이 좋습니다.

즉, 테스터데이터 파일을 만들고 이 파일을 입력하여(파일 입력 이용) 테스트하는 것이 좋습니다.
ii) 최종적인 프로그램을 goorm 사이트에 제출할 때, i)의 파일 입력 부분을 표준입력(cin.get 함수 이용)으로
변경하여 제출하면 됩니다.

4) 구름사이트에 테스트데이터 확인하기 바랍니다.

5)처음부터 문자들을 읽어 나가면서, 만나는 입력된 문자가 닫는 괄호 ) , ] , } 일 경우에 이전에 대응하는 여는 괄호 (, [, { 가 없을 경우에는 오류 1, 2, 3중 하나이다. 파일(입력된 문자)을 다 읽었을 때, 스택에 여는 괄호 (, [, { 가 남아있으면 스택의 가장 위에 있는 괄호에 대한 오류 4, 5, 6중 하나를 출력한다

#include <iostream>
#include <cstdlib>
 
using namespace std;
 
typedef char ItemType;
 
const int MAX_STACK_SIZE = 30;          // 스택의 최대 크기 설정
class Stack
{
   int top;                              // 스택에서 가장 위에 있는 요소의 배열위치
   ItemType data[MAX_STACK_SIZE];   // 요소를 저장하는 배열
public:
   Stack();             // 스택 생성자
   ~Stack();                  // 스택 소멸자
   bool isEmpty();
   bool isFull();
   void push(ItemType e);    // 스택에 요소 삽입
   ItemType pop();           // 가장 최근에 스택에 삽입된 요소를 삭제하고 반환
   ItemType peek();           // 가장 최근에 스택에 삽입된 요소를 반환
};
 
//오류 처리 함수
inline void error(const char *message) {
            cout << message << endl;
            exit(1);
}
 
Stack::Stack()       // 스택 생성자
{
   top = -1;
}
 
Stack::~Stack() {}           // 스택 소멸자
 
bool Stack::isEmpty()
{
   return top == -1;
}
 
bool Stack::isFull()
{
   return top == MAX_STACK_SIZE - 1;
}
 
void Stack::push(ItemType e)      // 스택에 요소 삽입
{
   if (isFull())
   {
      error("스택Full");
   }
   else
   {
      data[++top] = e;
   }
}
 
ItemType Stack::pop()         // 가장 최근에 스택에 삽입된 요소를 삭제하고 반환
{
   if (isEmpty())
      error("스택 Empty");
   return data[top--];
}
 
ItemType Stack::peek()        // 가장 최근에 스택에 삽입된 요소를 반환
{
   if (isEmpty())
      error("스택 Empty");
   return data[top];
}

File attachments: 
첨부파일 크기
Image icon 제목 없음.png52.38 KB
 의 이미지

"아무리 해봐도 안되네요. 어떻게 하는지 모르겠어요" 밖에 없는 질문은 답하기가 매우 곤란합니다.
질문자가 어느 정도 수준인지, 어디까지 시도해봤는지, 어디서 막혔는지, 어디서부터 설명드려야 하는지 하나도 모르는데, 무슨 답을 드리겠습니까.
답변을 바란다면 질문에도 성의를 보이셔야지요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.