Social Icons

twitterfacebookgoogle pluslinkedinemail

Monday 28 October 2013

Program for traversing a graph through BFS and DFS

Breadth-first search (BFS) and depth-first search (DFS) are two distinct orders in which to visit the vertices and edges of a graph. BFS radiates out from a root to visit vertices in order of their distance from the root. Thus closer nodes get visited first.

#include<stdio.h>
#define MAX 20
typedef enum boolean{false,true} bool;
int adj[MAX][MAX];
bool visited[MAX];
int n; /* Denotes number of nodes in the graph */
main()
{
int i,v,choice;
create_graph();
while(1)
{
printf("\n");
printf("1. Adjacency matrix\n");
printf("2. Depth First Search using stack\n");
printf("3. Depth First Search through recursion\n");
printf("4. Breadth First Search\n");
printf("5. Adjacent vertices\n");
printf("6. Components\n");
printf("7. Exit\n");
printf("Enter your choice : ");
scanf("%d",&choice);


Implementation of Binary Search Tree

                                 A binary search tree is a tree where each node has a left and right child. Either child, or both children, may be missing. Figure 3-2 illustrates a binary search tree. Assuming k represents the value of a given node, then a binary search tree also has the following property: all children to the left of the node have values smaller than k, and all children to the right of the node have values larger than k. The top of a tree is known as the root, and the exposed nodes at the bottom are known as leaves.                                                                                                                                                                                                                                    

Implementation of Binary Search Tree


# include <stdio.h>
# include <malloc.h>
struct node
{
int info;
struct node *lchild;
struct node *rchild;
}*root;
main()
{
int choice,num;
root=NULL;
clrscr();
while(1)
{
printf("\n");
printf("1.Insert\n");
printf("2.Delete\n");
printf("3.Inorder Traversal\n");
printf("6.Display\n");
printf("7.Quit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the number to be inserted : ");
scanf("%d",&num);
insert(num);
break;
case 2:
printf("Enter the number to be deleted : ");
scanf("%d",&num);
del(num);
break;
case 3:
inorder(root);
break;
case 6:
display(root,1);
break;
case 7:
exit();
default:
printf("Wrong choice\n");
}/*End of switch */
}/*End of while */
}/*End of main()*/
find(int item,struct node **par,struct node **loc)
{
struct node *ptr,*ptrsave;
if(root==NULL) /*tree empty*/
{
*loc=NULL;
*par=NULL;
return;
}
if(item==root->info) /*item is at root*/
{
*loc=root;
*par=NULL;
return;
}
/*Initialize ptr and ptrsave*/
if(item<root->info)
ptr=root->lchild;
else
ptr=root->rchild;
ptrsave=root;
while(ptr!=NULL)
{
if(item==ptr->info)
{ *loc=ptr;
*par=ptrsave;
return;
}
ptrsave=ptr;
if(item<ptr->info)
ptr=ptr->lchild;
else
ptr=ptr->rchild;
}/*End of while */
*loc=NULL; /*item not found*/
*par=ptrsave;
}/*End of find()*/
insert(int item)
{ struct node *tmp,*parent,*location;
find(item,&parent,&location);
if(location!=NULL)
{
printf("Item already present");
return;
}
tmp=(struct node *)malloc(sizeof(struct node));
tmp->info=item;
tmp->lchild=NULL;
tmp->rchild=NULL;
if(parent==NULL)
root=tmp;
else
if(item<parent->info)
parent->lchild=tmp;
else
parent->rchild=tmp;
}/*End of insert()*/
del(int item)
{
struct node *parent,*location;
if(root==NULL)
{
printf("Tree empty");
return;
}
find(item,&parent,&location);
if(location==NULL)
{
printf("Item not present in tree");
return;
}
if(location->lchild==NULL && location->rchild==NULL)
case_a(parent,location);
if(location->lchild!=NULL && location->rchild==NULL)
case_b(parent,location);
if(location->lchild==NULL && location->rchild!=NULL)
case_b(parent,location);
if(location->lchild!=NULL && location->rchild!=NULL)
case_c(parent,location);
free(location);
}/*End of del()*/
case_a(struct node *par,struct node *loc )
{
if(par==NULL) /*item to be deleted is root node*/
root=NULL;
else
if(loc==par->lchild)
par->lchild=NULL;
else
par->rchild=NULL;
}/*End of case_a()*/
case_b(struct node *par,struct node *loc)
{
struct node *child;
/*Initialize child*/
if(loc->lchild!=NULL) /*item to be deleted has lchild */
child=loc->lchild;
else /*item to be deleted has rchild */
child=loc->rchild;
if(par==NULL ) /*Item to be deleted is root node*/
root=child;
else
if( loc==par->lchild) /*item is lchild of its parent*/
par->lchild=child;
else /*item is rchild of its parent*/
par->rchild=child;
}/*End of case_b()*/
case_c(struct node *par,struct node *loc)
{
struct node *ptr,*ptrsave,*suc,*parsuc;
/*Find inorder successor and its parent*/
ptrsave=loc;
ptr=loc->rchild;
while(ptr->lchild!=NULL)
{
ptrsave=ptr;
ptr=ptr->lchild;
}
suc=ptr;
parsuc=ptrsave;
if(suc->lchild==NULL && suc->rchild==NULL)
case_a(parsuc,suc);
else
case_b(parsuc,suc);
if(par==NULL) /*if item to be deleted is root node */
root=suc;
else
if(loc==par->lchild)
par->lchild=suc;
else
par->rchild=suc;
suc->lchild=loc->lchild;
suc->rchild=loc->rchild;
}/*End of case_c()*/
inorder(struct node *ptr)
{
if(root==NULL)
{
printf("Tree is empty");
return;
}
if(ptr!=NULL)
{
inorder(ptr->lchild);
printf("%d ",ptr->info);
inorder(ptr->rchild);
}
}/*End of inorder()*/
display(struct node *ptr,int level)
{
int i;
if ( ptr!=NULL )
{
display(ptr->rchild, level+1);
printf("\n");
for (i = 0; i < level; i++)
printf(" ");
printf("%d", ptr->info);
display(ptr->lchild, level+1);
}/*End of if*/
}/*End of display()*/

Saturday 26 October 2013

fatal error call to a member function getusername() on a non-object in magento

Hello Friend,

when you get like this error "
Fatal error: Call to a member function getUsername() on a non-object in .../app/design/adminhtml/default/default/template/page/header.phtml on line 31".

Please  follow the steps


  1. Backup the var folder as (var-back)
  2. Create a new var directory
  3. Backup the locks folder as (locks-back) {if available}
  4. Create the locks directory



Thanks
Enjoy Your Self,

Favicon icon not display in IE OR Firefox or Chrome

Hello Friends,



When you want to try add Favicon icon and then its not display in IE please use following step to display favicon icon in IE.

1. Please following code

<head>
<link href="http://anantprajapati.blogspot.in/favicon.ico" rel="icon" type="image/x-icon"></link>
<link href="http://anantprajapati.blogspot.in/favicon.ico" rel="shortcut icon" type="image/x-icon"></link>
<link href="http://anantprajapati.blogspot.in/favicon.ico" rel="icon" type="image/vnd.microsoft.icon"></link>
</head>


Thursday 24 October 2013

How to display most popular or most viewed product in magento

Hello Friends,

You want to display Most Popular or Most Viewed Product in magento then please add following code in your script

If you want to display in ,.phtml file

$this->getLayout()->createBlock('catalog/product_mostviewed')->setTemplate('reports/product_viewed.phtml')->toHtml(); ?>

Wednesday 23 October 2013

How To Solve internal server 500 in magento


Hello Friends,

You are facing problem like "internal server 500" with magento installation on server or other.

its very easy to solve.

please follow the following step to resolved above issue.

1. First of all check rewrite module is enable on your server.
  if not enable then please enable it from php.ini file of server or .htaccess file or other way.


2. please check Folder permission through FTP or Cpanel


change permission  of  all the file and folder to 755

Friday 11 October 2013

How to create Zip file in php

Hello Friends,

You want  create ZIP file in php using programming...

its possible using following.


Thursday 10 October 2013

How to Alter , create new table, delete or update table using upgrade script in magento



Hello Friends,

You can perform database query in magento upgrade script.

you are facing problem with alter,update,delete or create new table in magento but its very easy just write defined code in your upgrade script and you can see your table is altered or insert
create or delete

you must create script for this like beloved name

Name of file : 

syntax : mysql4-upgrade-<old_version>-<new_version>.php
 
Ex : mysql4-upgrade-0.1.0-0.1.1.php

Now you have quesion is that how to find it rifgh?
but it also easy   please open your config.xml file of your module and check the version which is your old_version.

syntax for create , alter and delete table




<?php $this->startSetup()->run("<write your query>")->endSetup();?>

code for ALTER Table

<?php
$this->startSetup()->run("
   ALTER TABLE {$this->getTable('faqs')}
   ADD COLUMN `preview` text AFTER `steps`
")->endSetup();
?>

code for Create New Table


<?php
$this->startSetup()->run("
  
DROP TABLE IF EXISTS {$this->getTable('mytable')};
CREATE TABLE {$this->getTable('
mytable')} (
`entity_id` int(11) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`content` varchar(255) NOT NULL default '',
`status` smallint(6) NOT NULL default '0',
`created_time` datetime NULL,
`update_time` datetime NULL,
PRIMARY KEY (`entity_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

")->endSetup();
?>

code for DELETE Table
<?php
$this->startSetup()->run("
DELETE from table_name where column_name = value
")->endSetup();
?>


code for UPDATE Table
<?php
$this->startSetup()->run("
UPDATE table_name set column_name=value where column_name = value
")->endSetup();
?>

Thanks,


Enjoy Your Self


Wednesday 9 October 2013

how to add facebook likes, google plus, twitter tweet and pinterest button on site

Hello Friends,


If you want to add social button on your site look like image then please use the following code.

following code is used for facebook like button, twitter tweet box, google plus(G+) and pinterest.

how to use it???

just add following code i your site and just set the url, description and image to in this code.


Monday 7 October 2013

Android Secret codes

1. Phone Information, Usage andBattery – *#*#4636#*#*

2. IMEI Number – *#06#

3. Enter Service Menu On NewerPhones – *#0*#

4. Detailed Camera Information –*#*#34971539#*#*

5. Backup All Media Files –*#*#273282*255*663282*#*#*

6. Wireless LAN Test –*#*#232339#*#*

7. Enable Test Mode for Service –*#*#197328640#*#*

8. Back-light Test – *#*#0842#*#*

9. Test the Touchscreen –*#*#2664#*#*

10. Vibration Test – *#*#0842#*#*

 

Free Advertisement

Free Advertisement

Free Advertisement

Free Advertisement