**We need you to answer this question!**

###### If you know the answer to this question, please register to join our limited beta program and start the conversation right now!

## Related Questions

###### Asked in Computers

### Different data types?

###### Asked in C Programming

### C code for minimum spanning tree using kruskal's algorithm?

/* Program for creating a minimum spanning tree from
Kruskal's
algorithm */
#include
#define MAX 20
struct edge
{
int u;
int v;
int weight;
struct edge *link;
}*front = NULL;
int father[MAX]; /*Holds father of each node */
struct edge tree[MAX]; /* Will contain the edges of spanning
tree */
int n; /*Denotes total number of nodes in the graph */
int wt_tree=0; /*Weight of the spanning tree */
int count=0; /* Denotes number of edges included in the tree
*/
/* Functions */
void make_tree();
void insert_tree(int i,int j,int wt);
void insert_pque(int i,int j,int wt);
struct edge *del_pque();
main()
{
int i;
create_graph();
make_tree();
printf("Edges to be included in spanning tree are :\n");
for(i=1;i<=count;i++)
{
printf("%d->",tree[i].u);
printf("%d\n",tree[i].v);
}
printf("Weight of this minimum spanning tree is : %d\n",
wt_tree);
}/*End of main()*/
create_graph()
{
int i,wt,max_edges,origin,destin;
printf("Enter number of nodes : ");
scanf("%d",&n);
max_edges=n*(n-1)/2;
for(i=1;i<=max_edges;i++)
{
printf("Enter edge %d(0 0 to quit): ",i);
scanf("%d %d",&origin,&destin);
if( (origin==0) && (destin==0) )
break;
printf("Enter weight for this edge : ");
scanf("%d",&wt);
if( origin > n destin > n origin<=0 destin<=0)
{
printf("Invalid edge!\n");
i--;
}
else
insert_pque(origin,destin,wt);
}/*End of for*/
if(i
{
printf("Spanning tree is not possible\n");
exit(1);
}
}/*End of create_graph()*/
void make_tree()
{
struct edge *tmp;
int node1,node2,root_n1,root_n2;
while( count < n-1) /*Loop till n-1 edges included in the
tree*/
{
tmp=del_pque();
node1=tmp->u;
node2=tmp->v;
printf("n1=%d ",node1);
printf("n2=%d ",node2);
while( node1 > 0)
{
root_n1=node1;
node1=father[node1];
}
while( node2 >0 )
{
root_n2=node2;
node2=father[node2];
}
printf("rootn1=%d ",root_n1);
printf("rootn2=%d\n",root_n2);
if(root_n1!=root_n2)
{
insert_tree(tmp->u,tmp->v,tmp->weight);
wt_tree=wt_tree+tmp->weight;
father[root_n2]=root_n1;
}
}/*End of while*/
}/*End of make_tree()*/
/*Inserting an edge in the tree */
void insert_tree(int i,int j,int wt)
{
printf("This edge inserted in the spanning tree\n");
count++;
tree[count].u=i;
tree[count].v=j;
tree[count].weight=wt;
}/*End of insert_tree()*/
/*Inserting edges in the priority queue */
void insert_pque(int i,int j,int wt)
{
struct edge *tmp,*q;
tmp = (struct edge *)malloc(sizeof(struct edge));
tmp->u=i;
tmp->v=j;
tmp->weight = wt;
/*Queue is empty or edge to be added has weight less than first
edge*/
if( front NULL) /*Edge to be added at the end*/
tmp->link = NULL;
}/*End of else*/
}/*End of insert_pque()*/
/*Deleting an edge from the priority queue*/
struct edge *del_pque()
{
struct edge *tmp;
tmp = front;
printf("Edge processed is %d->%d
%d\n",tmp->u,tmp->v,tmp->weight);
front = front->link;
return tmp;
}/*End of del_pque()*/

###### Asked in C Programming, Numbers

### Program for count the total number of node in binary tree?

int count (const Tree *t)
{
int sum;
if (!t) return 0;
else sum=1;
if (t->left) sum += count (t->left);
if (t->right) sum += count (t->right);
return sum;
}
advanced:
int count (const Tree *t)
{
int sum= 0;
while (t) {
sum++;
if (t->left) {
if (t->right) sum += count (t->right);
t = t->left;
} else t = t->right;
}
return sum;
}

###### Asked in C++ Programming

### Program for binary search tree in c plus plus?

The following program makes use of a binary search tree to store
integers. The program generates 10 random numbers which are then
inserted into the tree. it then generates random numbers until it
locates three which are in the tree, and three which are not in the
tree.
#include<iostream>
#include<time.h>
class tree
{
private:
struct node
{
node(int num): data(num), left(NULL), right(NULL) {}
~node(){ delete(left); delete(right); }
int data;
node* left;
node* right;
void insert(int num)
{
if( num<data )
{
if( !left )
left = new node(num);
else
left->insert(num);
}
else
{
if( !right )
right = new node(num);
else
right->insert(num);
}
}
void print()
{
if( left )
left->print();
std::cout<<data<<std::endl;
if( right )
right->print();
}
bool find(int num)
{
if( num == data )
return( true );
if( num < data && left )
return( left->find( num ));
if( right )
return( right->find( num ));
return( false );
}
};
node* m_root;
public:
tree(): m_root(NULL){}
~tree(){ delete( m_root ); }
void insert(int num)
{
node* new_node = new node(num);
if( !m_root )
m_root = new_node;
else
m_root->insert(num);
}
void print()
{
if( m_root )
{
std::cout<<"The tree has the following
nodes"<<std::endl;
m_root->print();
}
else
std::cout<<"The tree is empty!\n"<<std::endl;
}
bool find(int num)
{
if( m_root )
return( m_root->find( num ));
return( false );
}
};
int main()
{
srand((unsigned) time(NULL));
// instantiate the tree
tree t;
// show the tree
t.print();
// insert 10 random numbers
for(int i=0; i<10; ++i)
t.insert( rand() );
// show the tree
t.print();
std::cout<<"\nSearching for three numbers in the
tree..."<<std::endl;
int count = 0;
while( count<3 )
{
int num = rand();
if( t.find( num ))
{
std::cout<<"The number "<<num<<" was
located!"<<std::endl;
++count;
}
}
std::cout<<"\nSearching for three numbers not in the
tree..."<<std::endl;
count = 0;
while( count<3 )
{
int num = rand();
if( !t.find( num ))
{
std::cout<<"The number "<<num<<" was not
located!"<<std::endl;
++count;
}
}
}
Example Output
The tree is empty!
The tree has the following nodes
3735
3759
6220
7922
14522
17096
19727
21238
24131
25922
Searching for three numbers in the tree...
The number 3735 was located!
The number 24131 was located!
The number 14522 was located!
Searching for three numbers not in the tree...
The number 31172 was not located!
The number 20853 was not located!
The number 30182 was not located!

###### Asked in Computer Programming, C Programming, Unix

### Program that takes a single integer argument n from the command line and creates a binary tree of processes of depth n?

#include <stdio.h>
#include <sys/types.h>
#include <pthread.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int process = 1;
int child[2];
int numChilds = 0;
int state;
int depth;
assert(argc 0)
{
numChilds = 0 ;
procId *= 2 ;
if (! --depth)
exit(0);
}
else
{
numChilds++ ;
process++ ;
}
}
while (numChilds) wait(&state);
}

###### Asked in C Programming

### Program to count the total number of leaf node and total number of intermidiet node?

void counts_core (const Tree *t, int *nleaf, int *nint)
{
if (t->left==NULL && t->right==NULL) ++*nleaf;
else {
++*nint;
if (t->left) counts_core (t->left, nleaf, nint);
if (t->right) counts_core (t->right, nleaf, nint);
}
}
void counts (const Tree *t, int *nleaf, int *nint)
{
*nleaf= 0;
*nint= 0;
if (t) counts_core (t, nleaf, nint);
}

###### Asked in C Programming, Computer Programming, Java Programming

### How do you make an array of 16?

In Java:
int[] myArray;
// or: int myArray[]
followed by:
myArray = new int[16];
Instead of int, you can use any other data type, including a
class.
In Java:
int[] myArray;
// or: int myArray[]
followed by:
myArray = new int[16];
Instead of int, you can use any other data type, including a
class.
In Java:
int[] myArray;
// or: int myArray[]
followed by:
myArray = new int[16];
Instead of int, you can use any other data type, including a
class.
In Java:
int[] myArray;
// or: int myArray[]
followed by:
myArray = new int[16];
Instead of int, you can use any other data type, including a
class.

###### Asked in C Programming, Computer Programming

### What is functions returning pointers?

#include<iostream>
using namespace std;
main()
{
int * add(int,int);
int *ptr;
int x,y;
cin>>x>>y;
ptr=add(x,y);//address of the result variable is assigned to
ptr
cout<<"result is"<<*ptr;
}
int *add(int a,int b)
{
int c=a+b;
return(&c);
}
#include<iostream>
using namespace std;
main()
{
int add(int,int);
int (*ptr)(int,int);//declaring function pointer
int x,y,result;
cin>>x>>y;
ptr=add //address of the function is assinged to ptr
result=(*ptr)(x,y);
}

###### Asked in The Difference Between

### What is the difference between function and recursive function?

I will explain in the easiest way the difference between the
function and recursive function in C language.
Simple Answer is argument of the function is differ but in the
recursive function it is same:)
Explanation:
Function
int function(int,int)// function declaration
main()
{
int n;
......
......
n=function(a,b);
}
int function(int c,int d)
{
......
......
......
}
recursive Function:
int recursive(int,int)// recursive Function declaration
main()
{
int n;
.....
.....
.....
.....
n=recursive(a,b);
}
int recursive(int a,int b)
{
.....
....
....
....
}
Carefully see, In the recursive Function the function arguments
are same.