#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&NBSP;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;} [[email protected] 20160731]$ g++ 0.cc[[email protected] 20160731]$ ./ a.out0 1 2 3 4 5 6 7 8 9 Preparation of //list 3 //the newly added node 691215182745 0 1 2 3 3 4 5 6 6 7 8 9 9 12 15 18 27 45 //the final situation [[email protected] 20160731]$
"List" can be used for Huffman tree to build a list method of selecting the number of alternative heap