April 29, 2012

Huffman Code in C/C++ with String as Node

Hi everyone,

I have copied someone's code and modified. But Since, the author has put the code as open source, I have done that for my friend.

Here it goes, Huffman code in C/C++

Source Code:
#include<conio.h>
#include<string.h>
#include<math.h>
#include<iostream.h>
#include<stdlib.h>

#define ARRAY_SIZE 20
#define MAX_NAME_LEN 25

int g,h,p,y,n;
char m[ARRAY_SIZE],b[ARRAY_SIZE][2],re;

int alpha = 65;

char name[ARRAY_SIZE][MAX_NAME_LEN];
int i=0,j=0,k=0;

/*
Perfoming operations
*/

//Tree Structure
struct tree
{
char a[20];
int s;
struct tree *left,*right;
}*root=NULL,*tt[20]={NULL},*temp,*temp2,*t2,*ri,*le;


// Queur Structure
struct pqu
{
int info;
char a[20];
struct pqu *ptr;
}*front=NULL,*t,*par,*t1,*p1,*p2;

// Pointer to queue
struct pqu* fp(int info)
{
struct pqu *p=NULL;
for(t1=front;t1->info<info&&t1!=NULL;t1=t1->ptr)
{
p=t1;
}
return (p);

}

//PUSH operation
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;
}
}
}

// POP operation
struct pqu* dequ()
{
t1=front;
front=front->ptr;
return t1;
}

//Get Info of a leaf
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;
}
}

// Insert Operation
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;
}
}

//Display Tree
void disp(struct tree *rt)
{
if(rt!=NULL)
{
disp(rt->left);
//cout<<””<<rt->a;disp(rt->right);
}
}

//Display Name
void displayname(int idx)
{
cout<<name[idx]<<”: ”;
}

/*
End of operations
*/


//Main Method

int main()
{
while(1)
{
//Clear Screen
clrscr();

cout<<”Enter the total no of leafs : ”;
cin>>n;


for(i=0;i<n;i++,alpha++)
{
cout<<”Enter Name: ”;
cin>>name[i];

//itoa(alpha,m,10);
//strcpy(m,(char*)alpha[i]);
*m=(char)alpha; //Assigning Local Values
strcpy(b[i],m);

cout<<”Enter frequency for ”<<name[i]<<” : ”;
cin>>g;

//Enque to the list
enqu(m,g);

} //Repeat till all the leafs data entered

insert(); // Form the tree
disp(root); // Display the codeword of leaf from root


for(i=0;i<n;i++)
{
displayname(i);
info(b[i]);
cout<<”n”;
}

cout<<”nDo You Want To Continue Y or N: ”;
cin>>re;
clrscr();
if(re=='y'||re=='Y')
continue;
else
break; //exit(0);
}

return 0;
}//end of while

Output:

I am also making this as an open source code. Anyone can edit, share, re-distribute the code.

For further queries, please mail to psrdotcom@gmail.com

April 27, 2012

Upgraded to Ubuntu 12.04 LTS from Ubuntu 11.10

Hi all,

Today I have upgraded my PC from Ubuntu 11.10 to Ubuntu 12.04 LTS.

Procedure:

I have downloaded the .iso file from Ubuntu.com
Burn the .iso file into a CD.
Booted from the CD and upgraded.

After upgrading some of the non-compatible softwares has been removed.

I manually found the un-installed softwares and installed it.

My Review:

Look and feel: Not much difference between 11.10 and 12.04
Features: Inbuilt privacy application to specify that, "Don't record activity"
Videos: Search Youtube videos and play directly

Lot more features to search ..

UPSC Civil Services Premilinary Examination 2012 e-admit card / Hall Ticket Download

Hi all Civil Services Aspirants,

You can download the UPSC Civil Services Preliminary Examination 2012 e-Admit card (Hall-Ticket) through this link.

http://www.upsc.gov.in/

Please follow the below instructions to download the e-Admit card.
  1. On the right side of the page, you will find the "What's new" section.
  2. Under "What's new" section, click on the e-Admit Card-Civil Services (Preliminary) Exam.,2012 
  3. Please read the instructions carefully.
  4. Click on the "Click Here" link from the page

Important Instructions are:

  • Exam will be conducted in 2 sessions
  • Morning session: 9:30AM to 11:30AM
  • Afternoon session: 2:30PM to 4:30PM
  • Please reach the examination hall before 20 minutes of the session start time
  • Candidates are not allowed after 10 minutes to session start time
  • Bring only the Black Ball Point Pen to the examination center
  • Produce the downloaded e-Admit card at the examination center
  • If the downloaded e-Admit card photograph is not clear then
    • Bring 2 Passport size photographs (For 2 sessions, Morning and Afternoon)
    • Photo Identity Proof such as Driving License, Passport, Ration Card or any Govt. approved card
  • Any electronic device is not allowed inside examination center
  • Last date to download the e-Admit Card is 16-May-2012
    • Note: They will send you the e-Admit card to your registered e-mail id with UPSC.

Download Link of the e-Admit Card

http://164.100.128.31/CSPDefault.aspx

Download Process:
 
By 3 ways, you can download the e-Admit card
  • Click on the above mentioned link
  • Choose any one option
    • Registration Number: At the time of registration you will get this. (or)
    • Roll Number: After registration completion, you will get a roll number. (or)
    • Name: You full name as per the certificate, Father name and mother name (without Initials)
  • Provide your Date of Birth
  • Enter the captcha(characters in the box)
  • Click on the "Submit" button
Your e-Admit card gets downloaded.

All the very best for your examination.

April 26, 2012

Shelr.tv, Record your Terminal / Console and Share Online

Hi friends,

If you want to share your terminal work with your friends/official/public.

About Shelr.tv: http://shelr.tv/about

I have uploaded a sample terminal work of mine. Just listing .txt file(s)



Click on the Play button to view the recorded work.

We can create and share online tutorials and lot more by using this. If you are interested to do so, please follow the below procedure to install and record using shelr.tv


Pre-Requisites:

  1. Any Linux OS, Mac OS X
  2. Ruby and Rubygems


Your Identity:

  • Register with Shelr.tv to create an account with your any one of the existing ID (GitHub, Twitter, Google, OpenID)
  • You will be getting your unique ID from Shelr.tv
  • Now you are ready to record your terminal work


Installation:

I have tried with Ubuntu 11.10.

Please see the installation process here.

As you can see the bold faced lines are the commands which has been executed.

user@user-Vostro-230:~$ sudo add-apt-repository ppa:gwibber-daily/ppa
You are about to add the following PPA to your system:
 PPA for gwibber-daily
 Daily builds of Gwibber trunk
Press [ENTER] to continue or ctrl-c to cancel adding it

Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.aTSMFL4Xlg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80/ --recv 06D1ED00EB802A66640696C8D0AFF96872D340A3
gpg: requesting key 72D340A3 from hkp server keyserver.ubuntu.com
gpg: key 72D340A3: public key "Launchpad PPA for gwibber-daily" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

user@user-Vostro-230:~$ sudo apt-get update
Reading package lists... Done
W: GPG error: http://ppa.launchpad.net oneiric Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 588CD9FC28446D73

user@user-Vostro-230:~$ sudo gem install shelr
Fetching: json-1.6.6.gem (100%)
Building native extensions.  This could take a while...
Fetching: shelr-0.15.1.gem (100%)
Successfully installed json-1.6.6
Successfully installed shelr-0.15.1
2 gems installed
Installing ri documentation for json-1.6.6...
Installing ri documentation for shelr-0.15.1...
Installing RDoc documentation for json-1.6.6...
Installing RDoc documentation for shelr-0.15.1...


Record:

  1. Setup the Shelr with your unique id
  2. Run the record command
  3. Play the recorded work
  4. Push the recorded work
    • You will be prompted with "Description" and "Tags" of the work
    • Once successfully published the work, you will get the link (URL) of published one


Please see the sample recording and publishing of work.

user@user-Vostro-230:~$ shelr setup 8333xxxxxxxxxxxxxxxxxx

user@user-Vostro-230:~$ shelr record
Provide some title for your record: PSR's First Shelr Record
/home/user/.local/share/shelr/1335339141/meta
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=> Your session started
=> Please, do not resize your terminal while recording
=> Press Ctrl+D or 'exit' to finish recording
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Script started, file is /home/user/.local/share/shelr/1335339141/typescript
user@user-Vostro-230:~$ ls -l *.txt
-rwxr-xr-x 1 user user 64 2011-05-12 15:52 mozilla.txt
user@user-Vostro-230:~$ exit
Script done, file is /home/user/.local/share/shelr/1335339141/typescript
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=> Session finished

Replay  : shelr play last
Publish : shelr push last
user@user-Vostro-230:~$ shelr play last
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
user@user-Vostro-230:~$ ls -l *.txt
-rwxr-xr-x 1 user user 64 2011-05-12 15:52 mozilla.txt
user@user-Vostro-230:~$ exit
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
user@user-Vostro-230:~$ shelr push last

Your record will be published under terms of
Creative Commons Attribution-ShareAlike 3.0 Unported

Description: PSR's First Recording using Shelr.tv
Tags (ex: howto, linux): Test, Shelr, Ubuntu, PSR
=> Record published!
user@user-Vostro-230:~$ 

For further queries, please mail to psrdotcom@gmail.com

April 17, 2012

Clojure - A dynamic programming language targets JVM

Hi friends,

I found this post will be useful for the beginners and intermediate dynamic programming language developers.

Clojure -- http://clojure.org/

To get started with Clojure please follow the below procedure


Sample Examples:
  1. Calculate 1+2+(3*4) = 15
  2. Show JOptionPane Message Dialog with some text
You can see the example content in the below screen



References:
http://clojure.org/downloads
http://clojure.org/getting_started

Featured Post

Java Introdcution

Please send your review and feedback to psrdotcom@gmail.com