Add to Favorites    Make Home Page 2544 Online  
 Language Categories  
 Our Services  

Home » C Home » Data Structures Home » HUFFMAN CODING (Mini Project)

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title HUFFMAN CODING (Mini Project)
Author G.KALAIARASU
Author Email kalaiarasutech [at] gmail.com
Description This program is very useful for engineers those who have been taking Information coding techniques as major.

Category C » Data Structures
Hits 417569
Code Select and Copy the Code
Code : #include<iostream.h> #include<string.h> #include<math.h> #include<stdlib.h> #include<conio.h> struct tree { char a[20]; int s; struct tree *left,*right; }*root=NULL,*tt[20]={NULL},*temp,*temp2,*t2,*ri,*le; struct pqu { int info; char a[20]; struct pqu *ptr; }*front=NULL,*t,*par,*t1,*p1,*p2; struct pqu* fp(int info) { struct pqu *p=NULL; for(t1=front;t1->info<info&&t1!=NULL;t1=t1->ptr) { p=t1; } return (p); } void enqu(char a[20],int p) { t=(struct pqu*)malloc(sizeof(struct pqu)); strcpy(t->a,a); t->info=p; t->ptr=NULL; if(front==NULL) { front=t; } else { par=fp(p); if(par==NULL) { t->ptr=front; front=t; } else { t->ptr=par->ptr; par->ptr=t; } } } struct pqu* dequ() { t1=front; front=front->ptr; return t1; } void info(char c[2]) { int m=0,i; temp2=root; while(strcmp(c,temp2->a)!=0) { t2=temp2->left; for(i=0;i<strlen(t2->a);i++) { if(t2->a[i]==c[0]) { temp2=temp2->left; m=1; cout<<"0"; break; } } if(m!=1) { temp2=temp2->right; cout<<1; } m=0; } } void insert() { char a1[20],b1[20],v1[20]; int i,j,z=0,l; while(front!=NULL) { p1=dequ(); strcpy(a1,p1->a); l=p1->info; p2=dequ(); if(p2==NULL) break; strcpy(b1,p2->a); strcpy(v1,a1); temp=(struct tree*)malloc(sizeof(struct tree)); strcpy(temp->a,strcat(v1,b1)); temp->s=l+p2->info; temp->left=NULL; temp->right=NULL; temp2=temp; root=temp; for(i=0;i<z;) { if(strcmp(tt[i]->a,a1)==0) { temp->left=tt[i]; for(l=i;l<z;l++) { tt[l]=tt[l+1]; } i=0; continue; } else if(strcmp(tt[i]->a,b1)==0) { temp->right=tt[i]; for(l=i;l<z;l++) { tt[l]=tt[l+1]; } i=0; continue; } i++; } if(temp->left==NULL) { le=(struct tree*)malloc(sizeof(struct tree)); strcpy(le->a,a1); le->left=NULL; le->right=NULL; temp2->left=le; } if(temp->right==NULL) { ri=(struct tree*)malloc(sizeof(struct tree)); strcpy(ri->a,b1); ri->left=NULL; ri->right=NULL; temp2->right=ri; } if(front!=NULL) enqu(temp2->a,temp2->s); tt[z++]=temp2; } } void disp(struct tree *rt) { if(rt!=NULL) { disp(rt->left); cout<<" "<<rt->a; disp(rt->right); } } void main() { textmode(MONO); int i=0,g,h,p,y,n; char m[20],b[20][2],re; while(1) { clrscr(); cout<<"=================================================================== ========"; cout<<" HUFFMAN CODING "; cout<<"=================================================================== ======== "; cout<<"Enter the total no of characters : "; cin>>n; for(i=0;i<n;i++) { cout<<" Enter the character : "; cin>>m; strcpy(b[i],m); cout<<" Enter frequency for "<<m<<" : "; cin>>g; enqu(m,g); } insert(); disp(root); clrscr(); cout<<"=================================================================== ============"; cout<<" The corresponding codes are..... "; cout<<"=================================================================== ============"; for(i=0;i<n;i++) { cout<<" "<<b[i]<<" : "; info(b[i]); } cout<<" DO YOU WANT TO CONTINUE Y OR N: "; cin>>re; if(re=='y'||re=='Y') continue; else exit(0); } }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi ¦Õ¤ ?¤Ð Ãß??ÝÐÝ
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=984


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review