亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? 哈夫曼算法.c

?? 數(shù)據(jù)結(jié)構(gòu)源碼
?? C
字號(hào):
#include<stdio.h> 
#include<malloc.h> 
#include<conio.h> 
#include<stdlib.h> 
#include<string.h> 

/*聲明兩種鏈表結(jié)構(gòu)----start*/ 
struct node_a{  /*鏈表1-----作用:用來統(tǒng)計(jì)文件中字符的個(gè)數(shù)和種類(通過count)*/ 
 char data; 
 int count; 
 struct node_a *next; 
 }; 
typedef struct node_a node,*list; 
list head=NULL; 

struct nodeb{  /*鏈表2-----作用:用來建立用相應(yīng)的編碼代替字符的新文件*/ 
 char data; 
 struct nodeb *next; 
}; 
typedef struct nodeb node_b,*list_b;  /*jiang bianma xieru wenjian*/ 
list_b head_b=NULL; 
/*聲明兩種鏈表結(jié)構(gòu)----end*/ 

/*哈夫曼算法種相關(guān)的3種結(jié)構(gòu)的聲明-----start*/ 
struct forest{   
 float weight; 
 int root; 
 }; 
struct alphabet{ 
 char symbol; 
 float probability; 
 int leaf; 
 char *bianma;       
 }; 
struct tree{ 
 int lchild; 
 int rchild; 
 int parent; 
 }; 
typedef struct tree *tree_ptr,tree_node; 
typedef struct forest *forest_ptr,forest_node; 
typedef struct alphabet *alphabet_ptr,alphabet_node; 
tree_ptr tree1; 
forest_ptr forest1; 
alphabet_ptr alphabet1; 
int lasttree,lastnode; 
int least,second; 
/*哈夫曼算法種相關(guān)的3種結(jié)構(gòu)的聲明-----end*/ 

/**************stack difination start****************/ 
struct stacknode{ 
  char *bian_ma; 
  struct stacknode *next; 
  }; 
typedef struct stacknode stack_node; 
typedef stack_node *link; 
link top=NULL; 

void push(char *item){ 
 link p; 
 if(top!=NULL){ 
   p=(link)malloc(sizeof(stack_node)); 
   if(p==NULL){ 
    printf("Memory allocation error!"); 
    return; 
    } 
   p->bian_ma=item; 
   p->next=top; 
   top=p; 
  } 
  else{ 
    top=(link)malloc(sizeof(stack_node)); 
    if(!top){ 
     printf("Memory allocation error!"); 
     return; 
     } 
    top->bian_ma=item; 
    top->next=NULL; 
  } 
 } 

void pop(void){ 
  link p; 
  p=top; 
  top=top->next; 
  free(p); 
 } 

void makenull(void){ 
  while(top!=NULL) 
   pop(); 
} 

int empty(){ 
  if(top==NULL) 
  return 1; 
  else 
  return 0; 
  } 

char* tops(void){ 
   return (top->bian_ma); 
} 

void display_stack(link s){ /*顯示棧重的內(nèi)容*/ 
 link ptr; 
 ptr=s; 
 while(ptr!=NULL){ 
  printf("%s",ptr->bian_ma); 
  ptr=ptr->next; 
  } 
 } 

  /***************************stack__difination is end************************/ 
void display(list h){ /*顯示鏈表1*/ 
list ptr; 
int i=1; 
ptr=h->next; 
while(ptr!=NULL){ 
 printf("%d,%c,%d\n",i,ptr->data,ptr->count); 
 i++; 
 ptr=ptr->next; 
 } 
} 
void display_b(list_b h){  /*顯示鏈表2*/ 
list_b ptr; 
int i=1; 
ptr=h->next; 
while(ptr!=NULL){ 
 printf("%d,%c\n",i,ptr->data); 
 i++; 
 ptr=ptr->next; 
 } 
} 

void insert(char item){  /*用于插入元素以建立鏈表1*/ 
 list temp,ptr; 
 int flag; 
 ptr=head->next; 
 if(ptr==NULL){ 
head->next=(list)malloc(sizeof(node)); 
   head->next->data=item; 
   head->next->count=1; 
   head->next->next=NULL; 
   } 
 else{ 
    while(ptr!=NULL){ 
     if(ptr->data==item){ 
     ptr->count=ptr->count+1; 
     flag=1; 
     } 
    ptr=ptr->next; 
        } 
   ptr=head; 
   if(flag==1) 
     return; 
   else{ 
     temp=ptr->next; 
     ptr->next=(list)malloc(sizeof(node)); 
     ptr->next->data=item; 
     ptr->next->count=1; 
     ptr->next->next=temp; 
   } 
 } 
} 

void insert_b(char item){  /*插入元素以建立鏈表2*/ 
  list_b ptr_b, temp_b; 
  ptr_b=head_b; 
  if(ptr_b->next==NULL){ 
    head_b->next=(list_b)malloc(sizeof(node_b)); 
    head_b->next->data=item; 
    head_b->next->next=NULL; 
    } 
  else{ 
    while(ptr_b->next!=NULL){ 
  ptr_b=ptr_b->next; 
  } 
    ptr_b->next=(list_b)malloc(sizeof(node_b)); 
    ptr_b->next->data=item; 
    ptr_b->next->next=NULL; 
    } 
} 

void search(void){ /*搜索文件并將文件中的數(shù)據(jù)分別存入作用不同的鏈表中*/ 
 FILE *fp; 
 list ptr; 
 char ch; 
 if((fp=fopen("test.txt","r"))==NULL) 
   printf("Reading error!\n"); 
 while(!feof(fp)){ 
   ch=getc(fp); 
   if(ferror(fp)){ 
     printf("error!\n"); 
     break; 
     } 
   if(ch==EOF) 
    break; 
   insert(ch);   /*插入元素進(jìn)鏈表1*/ 
   insert_b(ch); /*插入元素進(jìn)鏈表2*/ 
   } 
 printf("\n"); 
 fclose(fp); 
} 

void display_struct(int n){ /*顯示哈夫曼算法中的3個(gè)結(jié)構(gòu)樹組 */ 
int i=0; 
printf("\n\n=======================================\n\n"); 
printf("FOREST_STRUCT_ARRY :\n\n\n"); 
for(i=0;i<=n;i++){ 
printf("%f,%d\n",forest1[i].weight,forest1[i].root); 
} 
getch(); 
printf("\n\nALPHABET_STRUCT_ARRY :\n\n\n"); 
for(i=0;i<=n;i++){ 
 printf("%f,%d,%c\n",alphabet1[i].probability,alphabet1[i].leaf,alphabet1[i].symbol); 
} 
getch(); 
printf("\n\nTREE_STRUCT_ARRY :\n\n\n"); 
for(i=0;i<=2*n-1;i++) 
printf("%d,%d,%d\n",tree1[i].lchild,tree1[i].rchild,tree1[i].parent); 
printf("\n\n======================================\n\n"); 
getch(); 
} 

int init_struct(void){  /*初始化哈夫曼算法中3種結(jié)構(gòu)數(shù)組*/ 
list ptr; 
float count=.0; 
int i=1,n=0; 
ptr=head->next; 
while(ptr!=NULL){ 
 count=ptr->count+count; 
 n++; 
 ptr=ptr->next; 
 } 
ptr=head->next; 
forest1=(forest_ptr)malloc(sizeof(forest_node)*n+sizeof(forest_node)); 
alphabet1=(alphabet_ptr)malloc(sizeof(alphabet_node)*n+sizeof(alphabet_node)); 
tree1=(tree_ptr)malloc(sizeof(tree_node)*n*2-sizeof(tree_node)); 
forest1[0].weight=alphabet1[0].probability=0.0; 
forest1[0].root=alphabet1[0].leaf=0; 
alphabet1[0].symbol='0'; 
while(ptr!=NULL){ 
 forest1[i].weight=alphabet1[i].probability=ptr->count/count; 
 forest1[i].root=alphabet1[i].leaf=i; 
 alphabet1[i].symbol=ptr->data; 
 i++; 
 ptr=ptr->next; 
} 
for(i=0;i<=2*n-1;i++){ 
 tree1[i].lchild=0; 
 tree1[i].rchild=0; 
 tree1[i].parent=0; 
 } 
return n; 
} 

void creat(void){      /*創(chuàng)建正文文件test.txt*/ 
 FILE *fp,*out; 
 char ch; 
 if((fp=fopen("test.txt","r++"))==NULL) 
   printf("Creat error!\n"); 
 printf("Input the data:\n"); 
 ch=getch(); 
 putch(ch); 
 while(ch!='#'){ 
   putc(ch,fp); 
   ch=getch(); 
   putch(ch); 
   } 
   fclose(fp); 
 } 

void creat_bianma(int number){  /*根據(jù)哈夫曼算法建立文件中各種字符對(duì)應(yīng)的編碼*/ 
 int i,j,n; 
 int p; 
 char *bm=malloc(sizeof(char)*number); 
 for(n=1;n<=number;n++){ 
    j=i=n; 
    makenull(); 
    p=tree1[i].parent; 
    while(tree1[p].parent!=0){ 
if(tree1[p].lchild==i) 
     push("0"); 
 else 
     push("1"); 
i=p; 
p=tree1[p].parent; 
      } 

    if(tree1[p].lchild==i) 
 push("0"); 
    else 
 push("1"); 
    strcpy(bm," "); /*目的:使創(chuàng)建編碼文件中的各編碼中間存在間隔*/ 
    while(!empty()){ 
strcat(bm,tops()); 
pop(); 
} 
     alphabet1[j].bianma=malloc(sizeof(char)*number); 
     strcpy(alphabet1[j].bianma,bm); 
     printf("\n%c:%s",alphabet1[j].symbol,alphabet1[j].bianma); /*打印出相應(yīng)的編碼*/ 
     getch(); 
    } 
 } 


void write_new_file(int number){ /*根據(jù)相應(yīng)的編碼重新建立編碼文件*/ 
  FILE *fp; 
  list_b ptr; 
  int i; 
  char *ch=malloc(sizeof(char)*number); 
  ptr=head_b->next; 
  if((fp=fopen("bianma.txt","w"))==NULL) 
    printf("Write in a new file error!"); 
  else{ 
    while(ptr!=NULL){ 
      for(i=1;i<=number;i++){ 
if(ptr->data==alphabet1[i].symbol){ 
   strcpy(ch,alphabet1[i].bianma); 
   fputs(ch,fp); 
   } 
} 
      ptr=ptr->next; 
    } 
  } 
  fclose(fp); 
} 


void main(void){ 
int i,num; 
char ch; 
void huffman(void); 
void lightones(); 
head=(list)malloc(sizeof(node)); 
head->next=NULL; 
head->data='\0'; 
head->count=0; 
head_b=(list_b)malloc(sizeof(node_b)); 
head_b->data='\0'; 
head_b->next=NULL; 
do{ 
  system("cls"); 
  creat(); 
  search(); 
  printf("\nlianbiao1:\n"); 
  display(head);/*顯示鏈表1*/ 
  getch(); 
  printf("\nlianbiao2:\n"); 
  display_b(head_b); 
  getch(); 
  num=init_struct(); 
  printf("\n"); 
  printf("The 3 init_struct of huffman?\n"); 
  display_struct(num);/*顯示初始化的哈夫曼書的相關(guān)3個(gè)結(jié)構(gòu)數(shù)組*/ 
  lastnode=num; 
  lasttree=num; 
  huffman(); 
  printf("Now the 3 struct through huffman shuanfa\n"); 
  display_struct(num);/*顯示哈夫曼樹中相關(guān)的3種結(jié)構(gòu)(經(jīng)過哈夫曼算法處理)*/ 
  printf("\nThe bian_ma is:\n"); 
  creat_bianma(num); 
  write_new_file(num); 
  printf("\nDo you want to re_try(y/n)?"); 
  ch=getchar(); 
  }while(ch=='y'); 
  } 

/*哈夫曼算法-----defination_start*/ 
void lightones(void){ 
 int i; 
 if(forest1[1].weight<=forest1[2].weight){ 
    least=1; 
    second=2; 
    } 
 else{ 
    least=2; 
    second=1; 
    } 
 for(i=3;i<=lasttree;i++) 
   if(forest1[i].weight<forest1[least].weight){ 
second=least; 
least=i; 
} 
   else 
if(forest1[i].weight<forest1[second].weight) 
 second=i; 
} 

int creat_tree(int lefttree,int righttree){ 
  lastnode=lastnode+1; 
  tree1[lastnode].lchild=forest1[lefttree].root; 
  tree1[lastnode].rchild=forest1[righttree].root; 
  tree1[lastnode].parent=0; 
  tree1[forest1[lefttree].root].parent=lastnode; 
  tree1[forest1[righttree].root].parent=lastnode; 
  return(lastnode); 
} 

void huffman(void){ 
  int i,j; 
  int newroot; 
  while(lasttree>1){ 
    lightones(); 
    i=least; 
    j=second; 
    newroot=creat_tree(i,j); 
    forest1[i].weight=forest1[i].weight+forest1[j].weight; 
    forest1[i].root=newroot; 
    forest1[j]=forest1[lasttree]; 
    lasttree=lasttree-1; 
    } 
} 

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美成人video| 久久久777精品电影网影网| 美女一区二区久久| 亚洲视频免费看| 日韩欧美国产综合一区| 99re视频这里只有精品| 另类成人小视频在线| 一区二区三区av电影| 国产午夜精品久久| 日韩亚洲欧美综合| 欧美在线短视频| www.一区二区| 国产一区二区在线观看视频| 性做久久久久久久久| 国产精品入口麻豆九色| 日韩欧美亚洲另类制服综合在线| 日韩成人精品在线| 一区二区三区欧美视频| 中文字幕第一区| 亚洲精品在线电影| 7777女厕盗摄久久久| 欧美午夜精品免费| 91日韩一区二区三区| 成人一级片在线观看| 国产一区不卡在线| 麻豆精品一二三| 日韩高清一级片| 一区二区三国产精华液| 中文字幕综合网| 国产日产精品一区| 久久这里只有精品6| 精品国精品国产| 欧美一区二区三区四区久久 | 日本 国产 欧美色综合| 亚洲精品乱码久久久久| 18成人在线视频| 国产精品视频免费| 中文字幕的久久| 国产精品福利av| 中文字幕久久午夜不卡| 国产精品伦理在线| 国产精品久久久久影院色老大| 日韩欧美另类在线| 精品久久久久久久久久久久包黑料 | 成人理论电影网| 国产成人亚洲精品青草天美| 国产九九视频一区二区三区| 国产伦精品一区二区三区免费迷| 亚洲综合999| 夜夜爽夜夜爽精品视频| 亚洲国产成人va在线观看天堂| 亚洲黄色免费网站| 亚洲高清不卡在线| 日韩精品亚洲专区| 久久激情综合网| 国产成人在线免费观看| 成人av免费观看| 色综合久久中文字幕综合网| 91久久免费观看| 欧美自拍丝袜亚洲| 3atv一区二区三区| 精品区一区二区| 国产无遮挡一区二区三区毛片日本| 国产人久久人人人人爽| 国产精品色婷婷久久58| 亚洲激情网站免费观看| 亚洲一二三四久久| 裸体一区二区三区| 国产成人在线视频网址| 成人av小说网| 欧美人牲a欧美精品| 欧美本精品男人aⅴ天堂| 国产精品久久三区| 天堂在线亚洲视频| 国产成人精品免费看| 一本高清dvd不卡在线观看| 欧美精品v日韩精品v韩国精品v| 91精品久久久久久久久99蜜臂| 欧美成va人片在线观看| 国产精品久久久久久妇女6080| 亚洲视频一区二区在线观看| 免费在线观看视频一区| 国产宾馆实践打屁股91| 欧美日韩高清在线播放| 精品动漫一区二区三区在线观看| 久久久国产午夜精品| 亚洲人成小说网站色在线| 日韩精品视频网| 国产.精品.日韩.另类.中文.在线.播放 | 亚洲一区二区精品视频| 日韩av午夜在线观看| 不卡区在线中文字幕| 欧美日本在线播放| 国产欧美日本一区视频| 亚洲一区二区在线免费看| 日本成人在线一区| 99久久精品国产一区二区三区| 欧美色男人天堂| 国产日韩精品一区二区三区在线| 一区二区三区国产精华| 国产高清不卡一区| 欧美丰满高潮xxxx喷水动漫 | 国产亚洲美州欧州综合国| 亚洲欧美另类在线| 国产一区二区三区在线观看精品| 色综合婷婷久久| 久久综合九色综合97婷婷| 亚洲黄色免费电影| 国产成人精品网址| 欧美一级免费大片| 亚洲午夜一区二区三区| 丁香激情综合国产| 精品久久久久久久久久久院品网 | 精品精品国产高清a毛片牛牛| 中文字幕亚洲精品在线观看 | 一区二区三区波多野结衣在线观看 | 亚洲视频狠狠干| 国产精品自在欧美一区| 在线综合视频播放| 亚洲午夜久久久久久久久久久| 另类小说视频一区二区| 欧美日韩综合一区| 亚洲精品免费视频| 色婷婷精品大在线视频| 亚洲欧美视频在线观看| 成人av一区二区三区| 亚洲国产电影在线观看| 国产成人精品免费网站| 久久久精品2019中文字幕之3| 日韩国产成人精品| 欧美乱妇20p| 亚洲aaa精品| 欧美日韩国产精选| 视频在线观看91| 精品视频在线视频| 一区二区三区美女视频| 在线视频欧美精品| 亚洲精品国产无天堂网2021| 色哟哟国产精品| 一卡二卡欧美日韩| 91国在线观看| 亚洲一区二区视频在线| 在线视频国内一区二区| 亚洲最大成人网4388xx| 欧美亚洲综合网| 亚洲www啪成人一区二区麻豆| 日本韩国一区二区三区视频| 亚洲精品菠萝久久久久久久| 在线观看一区二区精品视频| 亚洲一区二区三区视频在线播放 | 91麻豆精品91久久久久久清纯 | 国产精品天干天干在观线| 成人一级片网址| 中文字幕亚洲欧美在线不卡| 色综合天天狠狠| 亚洲线精品一区二区三区| 欧美电影影音先锋| 激情综合色综合久久综合| 国产调教视频一区| 99久久精品国产网站| 亚洲国产欧美另类丝袜| 91精品国产免费久久综合| 精品一区二区三区免费毛片爱| 久久一二三国产| 不卡的av在线| 亚洲国产aⅴ天堂久久| 精品少妇一区二区三区视频免付费 | 在线成人av影院| 蜜桃av一区二区在线观看 | 欧美在线三级电影| 日本不卡中文字幕| 久久久影视传媒| 色综合中文字幕国产| 日韩高清不卡在线| 国产视频一区在线观看| 在线一区二区三区四区五区| 日韩在线卡一卡二| 国产欧美一区二区精品性色 | 欧美日本免费一区二区三区| 国内精品国产三级国产a久久| 国产精品初高中害羞小美女文| 在线观看91视频| 国产精一品亚洲二区在线视频| 一区二区中文字幕在线| 欧美一区二区人人喊爽| 成人av免费观看| 日本视频一区二区三区| 国产精品热久久久久夜色精品三区 | 一区二区三区影院| 日韩欧美国产三级电影视频| k8久久久一区二区三区| 免费在线观看成人| 成人免费小视频| 欧美大胆一级视频| 91成人国产精品| 国产在线不卡一区| 午夜久久久影院| 18涩涩午夜精品.www| 久久久综合视频| 67194成人在线观看|