数据结构——链表
struct NODE
{
char ch;
int weight;
int a[maxdeep];
struct NODE *lchild,*rchild;
};
typedef struct NODE* Node;
typedef struct NODE node;
Node insert(Node p)
{
if(head==NULL)
{
head=p;
}
else if(p->weight < head->weight || (p->weight == head->weight && p->ch < head->ch))
{
p->next=head;
head=p;
}
else
{
Node q,r;
q=head;
r=q->next; //两个指针同时走 只和第二个指针比较就可以了!!!
while(1)
{
if(r==NULL)
{
q->next=p;
break;
}
else if(p->weight < r->weight || (p->weight == r->weight && p->ch < r->ch))
{
q->next=p;
p->next=r;
break;
}
else
{
q=q->next;
r=q->next;
}
}
}
return head;
}