How to find the mirror image of a binary tree?
Refer to http://cslibrary.stanford.edu/110/BinaryTrees.html
void mirror(struct node* node) {
if (node==NULL) {
return;
}
else {
struct node* temp; // do the subtrees
mirror(node->left);
mirror(node->right); // swap the pointers in this node
temp = node->left;
node->left = node->right;
node->right = temp;
}
}
1.what is a Relationship in database management system?
Universal Product Codes
What is main difference between macro and subroutins?
marco expand where it invoked ,subroutine will go where the subroutine is defined....
Write a program that read and display double number?
class simple
{
public static void main(String[] args){System.out.println(new java.util.Scanner(System.in).nextDouble());}
}
On a RadioShack TRS 80, It is a Syntax Error
"Syntax Error 601"
Counting even and odd numbers algorithm?
#include
using std::cout;
using std::endl;
int main()
{
int arr[] = {2, 45, 34, 56, 56};//you define here your array of even and odd numbers
int arrSize = sizeof arr/sizeof arr[0];
int numEven = 0;
int numOdd = 0;
for (int i = 0; i < (arrSize - 1); i++)
{
if (arr[i] % 2 == 0)
{
numEven++;
}
else
{
numOdd++;
}
}
cout << endl << "Number of even numbers: " << numEven
<< endl << "Number of odd numbers: " << numOdd
<< endl;
system("PAUSE");
return 0;
}
How do you store a string of letters for example abcdeabcde each to an array?
In C programming you would use the following:
char a[] = "abcdeabcde";
If you wish to create an array with more than one string, use an array of character pointers instead:
char* a[] = {"abcde", "fgh", "ijklm", "nopq", "rstu", "vwxyz"};
Why compiler doesn't support space in between character array?
int main (void)
{
char msg [] = "You are wrong here, spaces are perfectly okay";
puts (msg);
return 0;
}
How do you assign or print special symbols in c plus plus?
UTF-16 strings or characters (std::wstring or wchar_t) are the best method of assigning and printing special symbols. UTF-8 encoding using std::string can be used to minimise memory consumption but still requires conversion to wide-string for printing purposes. However, if the symbols are within the range of extended ASCII character codes (0x00 to 0xff), then an unsigned char or std::string is all you really need.
Write a program in C to accept 10 integers and print them in reverse order using linked list?
# include<stdio.h>
# include<conio.h>
void main()
{
int arr[10];
int i,j,temp;
clrscr();
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
printf("\nSorted array elements :\n");
for(i=0;i<10;i++)
printf("%d ",arr[i]) ;
getch();
}
What are primary data structure?
A primary data structure is a data structure that is created without the use of other data structures, whereas a secondary data structure relies on a primary data structure. A data structure is an organized collection of data elements.
[NOTE: Be careful not to confuse the term data structure with the term data type. It is a common mistake. This answer addresses dat structures. Often people who ask about primary data structures or primitive data structures are really asking about primitve data types.]
Here is an example where an array is a primary data structure and a binary tree is a secondary data structure based on the array:
An array is a primary data structure -- it is a set of sequentially numbered data elements, such as an array of integers or an array of names -- name0, name, name2, ...
A binary tree is a data structure where each element (called a node) has a data component and pointers to it's left and right sub-trees. [Think of a directory of folders, but each folder can only have two sub-folders.] We can create an and store an array of nodes to set up the tree in languages like C++ or Java.
The root of the tree could be node 1 in the array, it would point to nodes 2 and 3. node 2 would point to nodes 4 and 5, while node 3 would point to nodes 6 and 7 .. and so on. generally node n point to nodes 2n and 2n+1. (You can start with node 0, but the math is a little easier if you start with node 1.)
The binary tree in this case is the secondary data structure, while the undelying array is the primary data structure.
What has the author C C Eldridge written?
C. C. Eldridge has written:
'British Imperialism in the 19th Century (Problems in Focus)'
How to write a program for mouse in microprocessor?
What type of interface does Linux use?
You need to be more clear in what type of "interface" you are inquiring about. Linux has it's own API (Application Programming Interface) and ABI (Application Binary Interface). If you are referring to the user interface, Linux can have a GUI, a command line, or even no interface at all.
C program to implement transposition cipher using key?
/*
* Transposition cipher cracker
*
* Algorithm used to find keys:
*
* n = keylength
* t = textlength
* a = t / n
* b = t % n
* d = accumulated rest terms
* k = wanted plain text position
* loc(k) = a * perm(k % n) + d(perm(k % n)) + k/n
*
* By Ben Ruijl, 2009
*
* compile: g++ -O2 col.cpp
*/
#include <iostream>
#include <cstring>
#define MAXKEY 20
const char* buffer = "irtyhockeibtdaamoelatcnsronhoniirttcacdeiunsihaioarnndgpruphahirgtoarnmclspstwe";
int buflength;
const char* crib = "computer";
int criblength;
void print(int* perm, int n)
{
int a = buflength / n;
int b = buflength % n;
//invert perm
int invperm[MAXKEY];
for (int i = 0; i < n; i++)
invperm[perm[i]] = i;
int d[MAXKEY] = {0};
for (int i = 1; i < n; i++)
{
d[i] = d[i -1];
if (invperm[i - 1] < b)
d[i]++;
}
std::cout << "Found: ";
for (int i = 0; i < buflength; i++)
std::cout << buffer[a * perm[i % n] + d[perm[i % n]] + i / n];
std::cout << std::endl;
}
bool checkperm(int* perm, int n)
{
int cribpos = 0;
int a = buflength / n;
int b = buflength % n;
//invert perm
int invperm[MAXKEY];
for (int i = 0; i < n; i++)
invperm[perm[i]] = i;
int d[MAXKEY] = {0};
for (int i = 1; i < n; i++)
{
d[i] = d[i -1];
if (invperm[i - 1] < b)
d[i]++;
}
for (int i = 0; i < buflength; i++)
{
if (buffer[a * perm[i % n] + d[perm[i % n]] + i / n] n - 1)
checkperm(v, n);
else
{
for (int i = start; i < n; i++)
{
int tmp = v[i];
v[i] = v[start];
v[start] = tmp;
permute(v, start + 1, n);
v[start] = v[i];
v[i] = tmp;
}
}
}
int main(int argv, char** argc)
{
int perm[MAXKEY];
for (int i = 0; i < MAXKEY; i++)
perm[i] = i;
buflength = strlen(buffer);
criblength = strlen(crib);
int curkey = 2; // start key
while (curkey < MAXKEY)
{
std::cout << "Testing key " << curkey << std::endl;
permute(perm, 0, curkey); // permutate keys
curkey++;
}
return 0;
}
What is the notation used to place block of statements in a looping structure in C plus plus?
for( ; ; )
{
statement_block;
}
while( conditional_expression )
{
statement_block;
}
do
{
statement_block;
}while( conditional_expression )
When did J B Coats write Where Could I go but to the Lord?
The song, "Where Could I Go but to the Lord", was written in 1940 by James (J. B.) Coats, a songwriter from the Gitano Community (Jones County), Mississippi. The inspiration for the song came some years earlier when Mr. Coats was at the bedside of one of his dying neighbors, an African-American gentleman named Joe Keyes.
Being a preacher, Mr. Coats had asked Mr. Keyes if he knew where he would spend eternity when he did. Mr. Keyes simply replied, "Where could I go but to the Lord?" Some years later, as he was away from home teaching a singing school, Mr. Coats finally included these words in a gospel song. Mr. Coats died in 1961.
Does c plus plus need a function named main?
If this is a homework assignment, you really should try to answer it on your own first, otherwise the value of the reinforcement of the lesson due to actually doing the assignment will be lost on you.
Every C or C++ program (but see below) needs one and only function named main. The standard prototype is int main (int argc, char *argv[]); The run-time library looks for main as its first function to call after startup initialization.
In a Microsoft Windows application, the entry point is winmain. Operation is similar, though parameters are different.
Can you give an example of a basic 'Hello World' program?
#include<iostream>
int main()
{
std::cout << "Hello world!" << std::endl;
return(0);
}
What is the c code for multistage graph?
#include<stdio.h>
#include<conio.h>
int G[50][50],n,i,j,h,k;
void FGraph();
int findR();
void main()
{
clrscr();
printf("\t\t\tmultistage graph");
printf("\n enter the no of vertices:");
scanf("%d",&n);
printf("\n there is a edge between the follwing vertices enter its weight else 0:\n");
for (i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
G[I][J]=0;
IF(I!=J)&&(i<J))
{
printf ("%d and%d:",i,j);
scanf(%d,&G[i][j]);
}
}
FGraph();
getch();
}
void FGraph()
{
int cost[50],d[50],p[50],r;
for(i=1;i<=n;i++)
cost[i]=0;
for(j=n-1;j>=1;j++)
{
r=findR(j+1);
cost[j]=G[j][r]+cost[r];
d[j]=r;
}
p[1]=1;p[k]=n;
for(j=2;j<k;j++)
p[i]=d[p[j-1]];
printf("%d-",d[1]);
for(j=2;j<n;j++)
{
if((d[j]==d[j-1])(d[j]==0))
continue;
if(d[j]<=n)
printf("%d-"d[j]);
}
printf("%d",n);
}
int findR(int cu)
{
int r1=n+1;
for(h=1;h<=n;h++)
{if((G[h][cu]!=0)&&(r1==n+1)){
r1=j;
continue;
}
if(G[h][cu]!=0)
{
if(G[h][cu]<G[r1][cu])
r1=h;
}}
return r1;
}sorry i have answerd in c++
IMAGINE you were a soldier fighting in the Civil War. How would you feel? Words found in level 3 questions include: Evaluating, Judging, Applying a principle, Speculationg, Imagining, Predicting, Hypothesizing.
What is matrix programming in C programming?
A matrix is a rectangular array of numbers or symbols arranged in rows and columns. The following section contains a list of C programs which perform the operations of Addition, Subtraction and Multiplication on the 2 matrices. The section also deals with evaluating the transpose of a given matrix. The transpose of a matrix is the interchange of rows and columns.The section also has programs on finding the trace of 2 matrices, calculating the sum and difference of two matrices. It also has a C program which is used to perform multiplication of a matrix using recursion.
C Program to Calculate the Addition or Subtraction & Trace of 2 MatricesC Program to Find the Transpose of a given Matrix
C Program to Compute the Product of Two Matrices