#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
#define NULL 0
#define LEN sizeof(struct ln)
typedef struct ln
{
char num;
int data;
struct ln *next;
}se;
typedef struct
{
int weight;
int parent,lchild,rchild;
}htnode,*huffmantree;
typedef char ** huffmancode;
void select(huffmantree ht,int n,int *s1,int *s2)
{
htnode *p;int i,j,k;
p=ht;k=1;
for(i=1;i<=n;++i)
{
if(ht[i].weight>=ht[k].weight) k=i;
}
j=k;
for(i=1;i<=n;++i)
{
if(p[i].parent==0 && (p[i].weight<=p[j].weight)) {*s1=i;j=i;}
else
if(p[i+1].parent==0 && (p[j].weight>=p[i+1].weight)) {*s1=i+1; j=i+1;}
}
j=k;
for(i=1;i<=n;++i)
{
if(p[i].parent==0 && (p[i].weight<=p[j].weight))
{
if(i==*s1) continue;
*s2=i;j=i;
}
else
if(p[i+1].parent==0 && (p[j].weight>=p[i+1].weight))
{
if(i+1==*s1) continue;
*s2=i+1; j=i+1;
}
}
}
se *paixu(se *head)
{
se *p,*q,*r,*s,*t;
t=s=r=p=head->next;q=p->next;
while(q)
{
r=q;
while(p->num<=r->num)
{
t=p;p=p->next;
if(p==q) break;