数据结构c语言版题库含答案,求数据结构c语言版的习题和答案?

7faed4903c445962fee24f33c78ec508.png

哈夫曼编/译码器

#include

#define MAX 1000

#define MAXSYMBS 30

#define MAXNODE 59

typedef struct

{

int weight;

int flag;

int parent;

int lchild;

}huffnode;

typedef struct

{

int bits[MAXSYMBS];

int start;

}huffcode;

main()

{

huffnode huff_node[MAXNODE];

huffnode huff_code[MAXSYMBS],cd;

int i,j,m1,m2,x1,x2,n,c,p;

char symbs[MAXSYMBS],symb;

clrscr();

printf("please input the leaf num of tree:\n");

scanf("%d",&n);

for (i=0;i<2*n-1;i++)

{

buff_node[i].weight=0;

buff_node[i].parent=0;

buff_node[i].flag=0;

buff_node[i].lchild=-1;

buff_node[i].rchild=-1;

}

printf("please input the weight of every leaf\n");

for (i=0;i

scanf("%d",&huff_node[i].weight);

for (i=0;i

{

n1=m2=MAX;

x1=x2=0;

for (j=0;j

{

if (huff_node[j].weight

{

m2=m1;

x2=x1;

m1=huff_node[j].weight;

x1=j;

}

else if (huff_node[j].weight

[j].flag==0)

m2=huff_node[j].weight;

x2=j;

}

}

huff_node[x1].parent=n+i;

huff_node[x2].parent=n+i;

huff_node[x1].flag=1;

huff_node[x2].flag=1;

buff_node[n+i].weight=buff_node[x1].weight+buff_node

[x2].weight

buff_node[n+i].lchild=x1;

buff_node[n+i].rchild=x2;

}

for (i=0;i

{

cd.start=n;

c=i;

p=huff_node[c].parent;

while(p!=0)

{

if (huff_node[p].lchild==c)

cd.bits[cd.start]=0;

else

cd.bits[cd.start]=1;

cd.start=cd.start-1;

c=p;

p=huff_node[p].parent;

}

cd.start++;

for (j=cd.start;j<=n;j++)

huff_code[i].bits[j]=cd.bits[j];

huff_code[i].start=cd.start;

}

puts("the hafman code are:");

for (i=0;i

{

for (j=huff_code[i].start;j<=n;j++)

printf("%10d,huff_code[i].bits[j]");

printf("\n");

}

puts("press any key to quit……");

getch();

}

约瑟夫环

#include

typedef struct node

{int num;

struct node *next;

}linklist;

linklist *creat(head,n)

linklist *head;

int n;

{linklist *s,*p;

int i;

s=(linklist *)malloc(sizeof(linklist));

head=s;

s->num=1;

p=s;

for(i=2;i<=n;i++)

{s=(linklist *)malloc(sizeof(linklist));

s->num=i;

p->next=s;

p=s;

}

p->next=head;

return head;

}

linklist *select(head,m)

linklist *head;

int m;

{linklist *p,*q;

int i,t,n;

p=head;

t=1;

q=p;

do

{p=q->next;

t=t+1;

if(t%n==0)

{printf("%4d",p->num);

q->next=p->next;

free(p);

}

else q=p;

}while(q==p);

head=p;

return(head);

}

main()

{int n,m;

linklist *head;

printf("input the total number\n");

scanf("%d",&n);

printf("input the number to call:\n");

scanf("%d",&m);

creat(head,n);

select(head,m);

printf("the last one :is\n",head->num);

}

◆◆

评论读取中....

请登录后再发表评论!

◆◆

修改失败,请稍后尝试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值