yours.ramesh
BAN USERif the above is the output...it is not sorted....you could see ...3, 3, 3, 2, 3, 3....
- yours.ramesh February 15, 2011Murali,
for variables like int i; declaration and definition (memory) happen at same time. please read the first answer to understand it. Thanks.
good catch Murthy.
first two lines should be
min = min(a[0], a[1]);
max = max(a[0], a[1]);
Then it should work. Or we can start i from 0. either way should work.
your solution looks good when we use it many times.
- yours.ramesh February 11, 2011volatile variables can be changed by either OS or any other thread or any other hardware. so the variables can change at any time.
- yours.ramesh February 10, 2011pointer can point to nothing (NULL pointer)
reference has to refer some object, it cant refer to nothing
if memory cant b allocated...malloc returns NULL
if memory cant b allocated...new throws exception
malloc returns void pointer
new returns the pointer to the object that is created (eg: A *a = new A(); returns pointer of type A)
malloc does not call constructor
new calls constructor
malloc does not initialize the memory.
calloc initialize all bits of memory allocated to 0.
malloc takes one arguments (number of bytes required)
calloc takes two parameters (number of blocks required, size of each block)
a virtual function or virtual method is a function or method whose behaviour can be overridden within an inheriting class by a function with the same signature. This concept is a very important part of the polymorphism portion of object-oriented programming (OOP).
- yours.ramesh February 10, 2011macro function: code is replaced for sure during preprocessing.
inline function: code may be or may not be replaced depending on the size of the function and other factors which depends on the compiler.
if we define all functions as inline, the executable size will be huge.
1. output: 100
2. { } signifies scope
3. dont know
what about other elements in the array, how may times they are repeated...are there any restrictions on that?
- yours.ramesh February 08, 2011there is a better solution with 3n/2 comparisons only.
idea:
min = a[0];
max = a[1];
//note: i incremented 2 at a time
for(i = 2; i < n ; i += 2) {
if (a[i] < a[i+1]) {
if (min > a[i])
min = a[i];
if (max < a[i+1])
max = a[i+1];
} else {
if (min > a[i+1])
min = a[i+1];
if (max < a[i])
max = a[i];
}
}
loop is n/2 times
each iteration 3 comparisons to decide min and max.
so 3n/2 comparions. let me know if it is not clear.
@Umesh. each time you are doing 2 comparisions (one for min, one for max). and it is for n-1 elements. so it is 2(n-1) comparisions i guess
- yours.ramesh February 06, 2011Adhi, it is exactly fibonacci series.
reason is
1. if n = 1, reaching 1st floor is only one way (in one step) so f(1) = 1
2. if n = 2, reaching 2nd floor is two ways (take two steps one a time or take two steps once) so f(2) = 2
f(3) = f(2) + f(1)...
f(n) = f(n-1) + f(n-2)
perfectly fibonacci series.
Azza, looks correct. even if overlap is there, we cant change the address of "dst". above code looks like changing the destination address. isnt it?
- yours.ramesh February 01, 2011Quick sort: worst case O(n^2)
average case O(nlogn)
best case O(n)
Merge sort: worst case, average case, best case O(nlogn)
Bubble sort: worst case, average case, best case O(n^2)
correct me if im wrong.
The difference between a non-virtual c++ member function and a virtual member function is, the non-virtual member functions are resolved at compile time. This mechanism is called static binding. Where as the c++ virtual member functions are resolved during run-time. This mechanism is known as dynamic binding.
- yours.ramesh January 28, 2011good solution Anurag
- yours.ramesh January 28, 2011
good link amit
- yours.ramesh February 17, 2011