189 8069 5689

【list】可用于哈夫曼树的一种建树选数的链表方法替代堆

#include
#include
#include
using namespace std;
int a[]={1,2,3,4,5,6,7,8,9};
struct node
{
node(int xx):x(xx),next(NULL){}
int x; 
 node *next;
};
void fun()
{
 
}
int main()
{
node *head=new node(0);
node *p=head;
for(int i=0;i<9;i++)
{
node *add=new node(a[i]);
p->next=add;
p=add;
}

 node *q=head;
while(q)
{
cout<x<<" ";
q=q->next;
}
cout<next;
q=p->next;
while(p->next!=NULL)
{

node *add=new node(p->x+q->x);
node  *qq=q; 
 while(add->x > qq->x && qq->next!=NULL)
     {
      qq=qq->next;
     }
  add->next=qq->next;
  qq->next=add;
  cout<x<next;
q=p->next;
}


 q=head;
while(q)
{
cout<x<<" ";
q=q->next;
}
cout<            
            
                        
分享文章:【list】可用于哈夫曼树的一种建树选数的链表方法替代堆
网页URL:http://cdxtjz.cn/article/pgghce.html

其他资讯