http://www.hackerschool.org/HS_Boards/zboard.php?id=QNA_programming&no=1311 [º¹»ç]
#include <stdio.h>
#include <stdlib.h>
#define stacksize 10 //stacksize ÀÇ Å©¸®¸¦ ³ªÅ¸³À´Ï´Ù.
void mpage(); //ÇÔ¼öµéÀ» Á¤ÀÇ Çß½À´Ï´Ù.
int push(double *,int);
int view(double *,int);
int pop(double *,int);
int input(double *);
int main()
{
double stack[stacksize]={0};//½ºÅÃÀÇ ÃʱâÈÀÔ´Ï´Ù.
mpage();
input(stack);
return 0;
}
int input(double *input_stack)
{
int input_count;
int count=0;
int pop_return=0;
for(count=0;count<=stacksize;) //¿©±â¼ ¾î¶² ÇÔ¼ö¸¦ È£ÃâÇÒ²¯Àΰ¡¸¦ °í¸¨´Ï´Ù.
{
scanf("%d",&input_count);
if(input_count==1)
{
push(input_stack,count);
count++;
}
else if(input_count==2)
{
count--;
pop_return=pop(input_stack,count);
if(pop_return==-1)
count++;
}
else if(input_count==3)
{
view(input_stack,count);
}
else // ¿¹¿Ü ó¸® ÀÔ´Ï´Ù.
printf("1,2,3 Áß ÅÃÀÏ Çؼ ÀÔ·ÂÇϼ¼¿ä");
}
return 0;
}
int push(double *push_stack,int push_count)
{
if(push_stack[push_count]==0)
{
if (push_count==stacksize+1)
{
fputs("stack overflow",stdout);
push_count--;
}
printf("\n %d ¹ø° ¸Þ¸ð¸®¿¡ ³ÖÀ» µ¥ÀÌŸ¸¦ ÀÔ·ÂÇϼ¼¿ä\n",push_count);
scanf("%s",push_stack[push_count]);
view(push_stack,push_count);
mpage();
return 0;
}
else
{
return 0;
}
return 0;
}
int view(double *view_stack,int view_count)
{
int view_for;
view_stack=(double *)malloc(sizeof(double)*stacksize);
if(view_stack==NULL)
{
puts("¸Þ¸ð¸® ÇÒ´ç¿¡ ½ÇÇÇ");
exit(1);
}
for(view_for=0;view_for<=stacksize;view_for++)
printf("%s",view_stack[view_for]);
free(view_stack);
return 0;
}
void mpage()
{
puts("\n##########################");
puts("# 1 . P U S H #");
puts("# #");
puts("# 2 . P O P #");
puts("# #");
puts("# 3 . V I E W #");
puts("##########################");
}
int pop(double *pop_stack,int pop_count)
{
if(*(pop_stack+pop_count)!=0)
{
if(pop_count==-1)
{
printf("´õÀÌ»ó »©³¾ µ¥ÀÌÅÍ°¡ ¾ø½À´Ï´Ù.underflow ÀÔ´Ï´Ù\n");
return -1;
}
printf("%d ¹ø° µ¥ÀÌÅ͸¦ »©³Â½À´Ï´Ù.",pop_count);
*(pop_stack+pop_count)=0;
mpage();
return 0;
}
return 0;
}
view ÇÔ¼ö¿¡¼ ÀÚ²Ù ¹®Á¦°¡ ¹ß»ýÇÏ³×¿ä ¤Ì¤Ì
¹ÌÄ¡°Ú¾î¿ä
|
Hit : 2842 Date : 2007/03/26 05:40
|