c++을 c#으로 ㅠ
떠나간그녀
#include iostream.h
?xml:namespace prefix = o ns = urn:schemas-microsoft-com:office:office /
const int max_len = 100; // 상수 최대 길이 10
class stack {
public: //외부 참조가 가능하도록 공개 선언
void push(int c)
{
top++;
if( top max_len )
s[top] = c;
else if( top == max_len )
cout 스택 풀상태endl;
}
char pop()
{
if( top == -1 )
cout 스택 비어있는 상태endl;
else
return (s[top--]);
}
void print()
{
int i;
for(i = 0; i = top; i++)
cout s[i] - endl;
}
stack();
private: //외부 참조가 가능하지 않게 비공개 선언
int s[max_len]; //스택배열 최대 길이
int top;
};
stack::stack()
{
top = -1;
}
void main()
{
stack a;
int data, select, value;
while(1)
{
cout ====================endl;
cout 1. pushendl;
cout 2. popendl;
cout 3. printendl;
cout 4. quitendl;
cout ====================endl;
cout select : ;
cin select;
switch(select)
{
case 1:
cout 입력 데이터 : ; //정수 엔 몇번째 데이터를 입력하세요
cin data; //정수 입력
a.push(data); //정수를 스택에 집어 넣음
break;
case 2:
value = a.pop() ;
cout value 값을 스택에서 빼따 우얄래endl;
break;
case 3:
a.print();
break;
case 4:
return;
break;
default:
cout 값을 잘못 입력 했다endl;
}
};
}
c++로 스택을 짜보았습니다.
이 코드를 c#코드로 좀 바꺼주실수 있나요?
틀은 그대로 하고 문법만 부탁드립니다.