⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 003.c

📁 用C语言实现数据结构的几种常用结构
💻 C
字号:
#include<stdlib.h>
#define MAX 100

int S[MAX];

int top1=-1;
int top2=MAX;


push()          /*压入堆栈*/
{
 int x,i,num;
 if(top1==top2)
   printf("Overflow.\n");
 else
 {printf("please input the data you want to push.\nthe data is:");
  scanf("%d",&x);
  printf("please input the stack you want to operate.\n\t*1 stack1.\n\t*2 stack2.\nthe choice is:");
  scanf("%d",&num);
  if(num==1)
   {top1++;
    S[top1]=x;
    printf("Successfully.\n");
   }
   else if(num==2)
   {top2--;
    S[top2]=x;
    printf("Successfully.\n");
   }
        else  printf("ERROR!\n");
  }
for(i=0;i<MAX;i++)
   printf("%d\t",S[i]);
}

pop()        /*取出数据*/
{int num;
 int y;
  if((top1==-1)&&(top2==MAX))
   printf("Underflow.\n");
  else
  { printf("please input the stack you want to operate.\n\t*1 stack1.\n\t*2 stack2.\nthe choice is:");
    scanf("%d",&num);
    if(num==1)
     {y=S[top1];
      top1--;
      printf("\nThe data is:%d",y);
     }
    else if(num==2)
        {y=S[top2];
         top2++;
          printf("\nThe data is:%d",y);
        }
         else  printf("ERROR!\n");
   }
}

show3()
{int choice;
 printf("\n***********************FUNCTION*********************************\n");
 printf("\t*1  push the element of stack.\n\t*2  pop the element of stack.\n\t*3 exit.\n");
 printf("\n***************************************************************\n");
 printf("please make the choice.\n");
 do
  {scanf("%d",&choice);
   if((choice<1)||(choice>3))
   printf("ERROR!please input again.\n");
  }while((choice<1)||(choice>3));
 return(choice);
}
stack()
{
 int choice;

  do
  {choice=show3();
   switch(choice)
    {case 1:{push();
             break;
             }
     case 2:{pop();
             break;
             }
     case 3:break;
    }
  }while(choice!=3);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -