How do you write c plus plus program to insert an element into a binary search tree?
Binary Search is an algorithm that finds an element by successively halving the search space. Typically, pointers are used, one for the beginning of an array, one for the end. Then a midpoint pointer is chosen, and a test is performed. You either find the element, or you discover that the target element is before or after the midpoint. You then adjust either the start pointer or the end pointer and you iterate. When you reach the point where the pointers are out of order, you conclude that the target is not found, and you also know where to insert it. Binary Search is best implemented with an ordered array, because you want to make "random" access to each element. The problem with arrays is that they are typically fixed size, and must be dynamically adjusted when they need to grow, a potentially "expensive" operation. You can also implement a Binary Tree, but there is cost in development and processing. Even trees have issues because, when inserting and deleting elements, you must use a rebalancing algorithm, otherwise the tree might degrade to a linked list, which is not efficient when used as a search space. In C++, it is possible to declare and define a class of elements that you can add to, subtract from, and search. If you do this correctly, you could start with a static or dynamic array, and then upgrade if need be to a binary tree, and then upgrade if need be to a balanced binary tree, all the while without requiring change to the public interface. That is perhaps the most important value of an Object Oriented Language such as C++.
How do you write a program in c to compute the power of a number without using the mathh library?
There is a function which can do it for you. You have to include math.h in headers. And then use the function pow(x, y) which returns a value of type double (x and y are double too).
pow(x, y) = x to the power of y.
Assembly language program to find the largest of series of numbers in 8051?
include irvine32.inc
.data
istno db "enter ist no",0
2nd db "enter second no",0
lagest db "largest no",0
.code
main proc
mov edx,offset istno
call writestring
call readint
call crlf
mov bx,ax
mov edx,offset 2nd
call writestring
call readint
call crlf
jg loop
loop;
mov edx,offset lagest
call writestring
call writeint
main endp
end main
assembly program to find the greatest of between two numbers is as follows:
Program
MVI B, 30H
MVI C, 40H
MOV A, B
CMP C
JZ EQU
JC GRT
OUT PORT1
HLT
EQU: MVI A, 01H
OUT PORT1
HLT
GRT: MOV A, C
OUT PORT1
HLT
Why should one learn C programming language?
C++ is a general purpose, cross platform, object oriented language that evolved from C. We learn it because although there are simpler high-level languages such as Java available, the amount of abstraction involved in these languages is both an advantage and a disadvantage. The advantage is that by separating the source code from the machine, you can write one program that can execute on many different machines, or platforms, without the need to compile separately upon each machine. The disadvantage is that the executable must be interpreted by a virtual machine, which translates the abstract instructions into machine-executable instructions. This results in greatly reduced performance and greater memory requires.
C++ code is just as portable as Java, but it requires a good deal more effort on the part of the programmer. However, the result is code that is comparable to that of assembly language in terms of efficiency, but with sufficient abstraction to produce machine code far more easily than with assembler alone. Although the learning curve is steeper than with Java, it is not as steep as that of assembler, and the skills learned from programming in C++ are highly transferable, largely due to the lower level of abstraction.
C++ is also the most popular language in use today thanks to its high performance and efficiency, and is particularly useful in developing operating system code, real time applications, games and such-like, as well as more general purpose uses. Newer languages such as Java have much in common with C++ (and much that is different), and although Java's popularity has grown, thanks to the mobile market and particularly in non-industrial applications (such as iPhone applets), C++ remains as popular as ever because, without C++, there would far fewer, newer platforms upon which to run Java applications.
Difference between const in C and final in Java?
Static:
we can use the keyword static either to method or to a variable.
when we declare to a method,(eg: public static void main(String args[]),we can use this method without any object.
when we use to a variable,there will be only one instance of that variable irrespective of how many objects that get created of that class.
Final:
Usage of final to method or to a variable makes them as constant. It's value cannot be changed...
Which is the syntax used for passing a structure member as an argument to a function?
You can pass the address by using '&' with the pointer variable, while passing actual arguments. In formal arguments '*' is used in the place of '&'. To pass the address of a pointer variable a double pointer variable should be used .
# include
Or:
# include
int main (void)
{ puts ("ABCDEFGFEDCBA ABCDEF FEDCBA ABCDE EDCBA ABCD DCBA ABC CBA AB BA"); return 0; }
Which operator can be used in some situations to simplify nested selection structures?
The ternary conditional operator:
x = a ? b : c;
This is the literal equivalent of the following if statement:
if (a) {
x = b;
} else {
x = c;
}
Note that a, b and c are all expressions (or compound expressions). Expression a must be a Boolean expression (evaluating true or false) while expressions b and c must be implicitly convertible to x's data type.
A real-world example:
// Return the larger of any two integers
int max (int a, int b) {
return a>b ? a : b;
}
What is maximum length of variable in c?
The maximum length of a variable is dependent on the platform. In a 32 bit platform, this might be 4 bytes, although the compiler and run-time library might support 64 bit, or 8 byte variables. In a 64 bit platform, the length might be 8 bytes.
(Arrays, strings, structures, classes, etc. are aggregated types, not scalar types, so they don't count in this answer.)
When do we make a virtual function pure?
We make a virtual function pure whenever we wish to make our class an abstract base class (an abstract data type). Unlike a virtual function, pure virtual functions must be overridden by a derived class or by one of its derivatives (the function remains pure virtual until it is overridden, at which point it becomes virtual). Derived classes that do not provide a complete implementation for all the pure virtual functions it inherits become abstract themselves. You cannot instantiate an abstract base class other than through derivation.
What are break and continue statement in c language?
Break is used to exit the closest loop. Continue will cause the program to go to the beginning of the loop.
for(int x=0;x<10;x++)
{
//continue;
for(int y=0;y<10;y++)
{
break;
}
}
The break statement causes the inner loop to stop at the first iteration. If the continue statement was uncommented, the inner loop would never be executed because the program would jump back to the beginning(until x = 10 of course).
What is worst case complexity of quick sort?
Selection sort has no end conditions built in, so it will always compare every element with every other element.
This gives it a best-, worst-, and average-case complexity of O(n2).
To find the largest element of an array in c plus plus?
int GetMaxElement( void * array)
{
if (array != 0)
{
return(max(array[], typeof(array)));
}
return(0);
}
Is c or c a procedural oriented language?
One definition of a "procedural programming language" is a language that is used to describe how a program should accomplish the task it is to perform. This is in opposition to a "declarative programming language" that is used to describe what the program should accomplish rather than how it accomplishes the task.
What is a definition of data types?
A data type is, well, the type of data. The most common types are strings (text with spaces, punctuation, etc), integers (whole numbers within a certain range, depending on the specific type), and decimal numbers (1.7). Depending on the database software, there will be many other types.
Write a c program to accept 3 digits and print all possible combinations from these digits?
Everyone i am ajay Verma and i answer this question, Write this programe in note pad:-
using System;
class MyClass
{
public static void Main(string [] args)
{
int n,d,result=1,sum=0;
Console.WriteLine("Enter any Number");
n=Convert.ToInt32(Console.ReadLine());
for(;n>0;)
{
d=n%10;
Console.WriteLine(d);
n=n/10;
}
}
}
How do you explain characteristics of algorithm?
Characteristics of algorithms are:
Finiteness: terminates after a finite number of steps
Definiteness: rigorously and unambiguously specified
Input: valid inputs are clearly specified
Output: can be proved to produce the correct output given a valid input
Effectiveness: steps are sufficiently simple and basic.
What does compiler mean in programming?
A compiler is a program that converts the language into machine code, also known as binary (1s and 0s). Not all programming languages need compilers. Some are assembly and still others can just be straight and utter machine code.
The maximum number of elements will depend on the type of array and the available memory. An array of char requires only 1 byte per element but an array of pointers requires 4 bytes per element (8 bytes on 64-bit systems). Arrays of objects or structures would likely require more memory per element.
For all practical purposes, the maximum size is 2,147,483,647 elements, which is the maximum positive range for a 4-byte integer (0x7FFFFFFF). At 1 byte per element, that works out at 2GB.
Distinct threadlike structures containing genetic information are called?
They may be called several things. They could be called Chromosomes (however these are when the genetic information has been aggregated into bodies (usually resembling an X). It can be called DNA (meaning deoxyribonucleic acid) which is the long strand of information made of up base pairs which resembles a twisted ladder. A small segment of that ladder which produces only one protein may be called a Gene. (from whence we get the term genetics).
When DNA is being used to make pieces of the cell and produce stuff in genera, it is transcoded into RNA (Ribonucleic Acid) which is a temporary form of the genetic information which can be taken from the nucleus of the cell where the DNA is stored and turned into protein elsewhere. This form of RNA is known as Messenger (m)RNA.
containing genetic information: Chromatin condenses to form chromosomes. These distinct, threadlike structures contain the genetic information or DNA.
How can you change the value of a constant variable in C?
You can change a static variable by putting the static variable into a function that has operations that you intend to execute upon the variable. Example, you want to change the static variable to another value or make an addition of 2. Put the source code inside a function with the static variable declared locally within the function.
Every time you call the function, the static variable value will change. Take note that the static variable retains the last value you declared it in your function call.
A more terse answerLocal variables declared as static are changed as normal; they are special in that their values persist across function calls.How can you write a c program that prints a table of trigonometric values for sin cos and tan?
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
const float pi=3.14;
float angle,radian;
clrscr();
printf("Angle\t Radian\t\t sin\t\t cos\t\t tangent");
for(angle=0;angle<=180;angle+=10)
{
radian=(pi/180.0)*angle;
printf("\n%0.0f\t%f\t%f\t%f\t%f",angle,radian,sin(radian),cos(radian),tan(radian));
}
getch();
}
Write c program to check the password?
What programming language is use to create a website?
At the most basic level is HTML and CSS. CSS is used mostly for the layout and visual design of the website. Usually combined with those is JavaScript. However, more and more websites are using PHP and MySQL. These are becoming more popular and if you ever want to have a website with multiple user accounts that your visitors can log into, PHP is probably the way to go. Might as well start out with it, then add this ability later when you're ready for it.
Write a program on Trace of matrix in C?
#include <conio.h>
#include <stdio.h>
void main()
{
int a[16][16];
int c=1,i,j,k,m=0,n,x;
clrscr();
printf("Enter the number of rows and columns for the square matrix \n");
scanf("%d",&n);
x=n;
while(n>=1)
{
for(k=0;k<n;k++)
a[m][k+m]=c++;
for(k=1;k<n;k++)
a[k+m][n-1+m]=c++;
for(k=n-2;k>=0;k--)
a[n-1+m][k+m]=c++;
for(k=n-2;k>0;k--)
a[k+m][m]=c++;
n=n-2;
m=m+1;
}
for(i=0;i<x;i++)
{
for(j=0;j<x;j++)
{
printf("%5d",a[i][j]);
}
printf("\n");
}
getch();
}