sllist.h

来自「Huffman编码及译码 1.将给定字符文件编码:生成编码」· C头文件 代码 · 共 64 行

H
64
字号
////按权有序(从小到大)的链表类
#ifndef SLLIST_H
#define SLLIST_H

class node{
public:
		HuffTree htree;
		node *next;
};

class SLList{
	node *head;
    int listcount;
	void init(){
           
	    head=new node;
	    head->next=NULL;
        listcount=0;
	}
	void removeall(){
		node * fence;
		while(head!=NULL){
		    fence=head;
			head=head->next;
			delete fence;		
		}	
	}
public:
	SLList(){
		init();
	}
	SLList(HuffTree*){
	}
	~SLList(){
		removeall();
	}
	void traverse(){	
	  for(node*nptmp=head->next;nptmp!=NULL;nptmp=nptmp->next)
		  cout<<nptmp->htree.root()->weight()<<" ";
	}
	int Listcount(){
		return listcount;
	
	}
    bool insert(HuffTree *htreein){	
		 node *tmp=new node;
		 tmp->htree=*htreein;
		 for(node *nptmp=head;nptmp->next!=NULL&&(nptmp->next->htree.weight())<(htreein->weight());nptmp=nptmp->next);
	             tmp->next=nptmp->next;
		         nptmp->next=tmp;
                 listcount++;
		
         return true;
	};
    bool remove(HuffTree *htreeout){
		*htreeout=head->next->htree;
		node* tmp=head->next;
		head->next=tmp->next;
		listcount--;
	        delete tmp;
		return true;
	};
};
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?