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

📄 pai.c

📁 用c写的数据结构问题
💻 C
字号:
#include"stdio.h"
#include"conio.h"
#define N  10


struct stack;
typedef struct stack *pstack;
struct stack
{
 int data[N];
 int n;
 };
int n;
pstack initial_stack(void)
{
 pstack p;
 int i,j;
 p=(pstack)malloc(sizeof(struct stack));
 if(p==NULL)exit(0);
 p->n=-1;
 printf("input n:\n");
 scanf("%d",&n);
 for(i=0;i<n;i++)
   {p->data[i]=i+1;
    p->n++;}
 return(p);
 }

void display(pstack p,int l[],int m)
{
 pstack q[N];
 int i,k,j,m1[N],r[N][N];
 if(p->n==-1)
  {for(i=0;i<n;i++)printf("%d",l[i]);}
  else
  {for(i=0;i<=p->n;i++)
    {
     q[i]=(pstack)malloc(sizeof(struct stack));
     if(q[i]==NULL)exit(0);
     for(j=0;j<i;j++)q[i]->data[j]=p->data[j];
     for(;j<p->n;j++)q[i]->data[j]=p->data[j+1];
     q[i]->n=p->n-1;
     for(j=0;j<=m;j++)r[i][j]=l[j];
     r[i][j]=p->data[i];
     m1[i]=m+1;
     display(q[i],r[i],m1[i]);
     printf(" ");
     }
   }
 }
main()
{
 pstack p;
 int flag;
 int m=-1,s[N];
 do{
 clrscr();
 p=initial_stack();
 display(p,s,m);
 scanf("%d",&flag);
 }while(flag);
 getch();
}

⌨️ 快捷键说明

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