#include<stdio.h>
#include<stdlib.h>
#include<iostream>
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<<q->x<<" ";
q=q->next;
}
cout<<endl;
p=head->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<<add->x<<endl;
p=q->next;
q=p->next;
}
q=head;
while(q)
{
cout<<q->x<<" ";
q=q->next;
}
cout<<endl;
return 0;
}
[sts@bogon 20160731]$ g++ 0.cc
[sts@bogon 20160731]$ ./a.out
0 1 2 3 4 5 6 7 8 9 //鏈表的準(zhǔn)備
3 //新添加的結(jié)點(diǎn)
6
9
12
15
18
27
45
0 1 2 3 3 4 5 6 6 7 8 9 9 12 15 18 27 45 //最后的情況
[sts@bogon 20160731]$
當(dāng)前名稱:【list】可用于哈夫曼樹的一種建樹選數(shù)的鏈表方法替代堆
本文鏈接:http://chinadenli.net/article24/pgghce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、外貿(mào)建站、電子商務(wù)、ChatGPT、App開發(fā)、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)