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

📄 ting3.bak

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

struct seqstack;
typedef struct seqstack *pseqstack;
struct seqstack
{
 int number[N];
 int n;
 };
int total=0;

pseqstack create_seq(void)
{
 pseqstack p;
 p=(pseqstack)malloc(sizeof(struct seqstack));
 if(p==NULL)
   printf("out of space");
 else
   p->n=-1;
 return(p);
 }

void initial_seq(void)
{
 int i;
 pseqstack p;
 p=create_seq();
 if(p==NULL)exit(0);
 for(i=0;i<N;i++)
 {
  p->number[i]=N-i;
  p->n++;
  }
 display_line(p);
 }

display_line(pseqstack p)
{
 int i,j,k,temp1,temp2,temp;
 pseqstack q[N];
 if(p->n==-1)return;
 for(i=p->n;i>=0;i--)
  {
   temp=p->number[i];
   printf("%d ",temp);
   q[i]=(pseqstack)malloc(sizeof(struct seqstack));
   if(q[i]==NULL)exit(0);
   for(j=0;j<i;j++)
     q[i]->number[j]=p->number[j];
   for(;j<p->n;j++)
    q[i]->number[j]=p->number[j+1];
    q[i]->n=p->n-1;
   for(k=i;k<q[i]->n;k++)
   {
     temp1=k;
     for(j=k+1;j<=q[i]->n;j++)
       if(q[i]->number[temp1]>q[i]->number[j])
	 temp1=j;
     if(temp1!=k)
      {
       temp2=q[i]->number[temp1];
       q[i]->number[temp1]=q[i]->number[k];
       q[i]->number[k]=temp2;
       }
    }
   display_line(q[i]);
   while(p->number[i]>p->number[i-1])i--;
   total++;

   }
  }

main()
{
 clrscr();
 initial_seq();
 printf("\ntotal=%d\n",total);
 getch();
 }

⌨️ 快捷键说明

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