ridercoder
BAN USERmake global volatile variable " flag "shared by both ISR and fun;
fun(){
time_t beg // read time ISR called
while( flag); // wait ISR to finish;
time_t end; //read time ISR exist
check end-beg>20;
}
plz correct it if wrong...
but i will also like to add
The expression (&b > a) is undefined.
The result of comparing two pointers using is defined only if the two pointers point to elements within the same array or structure.
The standard says nothing about the direction of the stack or if a stack even exists.
You can call some function. Optimizer cannot change call's stack frame.
Something like that:
int* foo()
{
int a;
return &a;
}
bool bar()
{
int b;
int* pa = foo();
return pa > &b;
}
well you can also use "inplace counting sort" also
- ridercoder November 01, 2010well i think vector is dynamic array ...
- ridercoder November 01, 2010suppose array is {3,5,1,4} and range is 1-5 missing numeber is 2
so XOR of array is 3^5^1^4
and XOR OF RANGE is 1^2^3^4^5
because XOR of two number is 0 ....
(1^2^3^4^5)^(3^5^1^4)=2 result
@radhika your solution is o(n logn ) but o(n) solution exist ....as told by sumeet
- ridercoder October 31, 2010sorting takes o(nlogn) time you can use hashtable
1. start from array check if number is already present in hashtable or not if no put inplace in array
2.if yes check next element..
so o(n) time and o(1) space
i think first we have to maintain searching and insertion mutually exclusive (like consumer and produce) when we search element should store in buffer and when search complete we can search ..
suppose at instant no key value not found i have n element and more element can come .
if we enter in search insertion is lock ..
in search
check 2^0 and 2^1 2^2 ... untill either array ends or at 2^i > search key if second one work .. now we know that at this instan search key is in between 2^(i-1) / 2^i now do binary search if element is present then return ;
now open lock ..means now we can insert element ...after this new element came .... again if we enter in search then we have to look only from previous 2^(i-1) because
search key when ever comes will be placed furthur from previous 2^(i-1) in array
keep this continuing untill we find array
why we need to check low<n in
"if (low < n && array[low] == key)"
low will be always <n in any case ??
@fragzilla it is not said all number lies between 1 to n it can be >n
ex 1 1000 1 then your answer will be 1000 .
but this will help only max number in array is less than array range can we have any better solution?
- ridercoder October 22, 2010in c i think its macro
#define sizeof(A) (char*((A*)1+1)- (char*)(A*)1);
is impletend in C++ by template function ??
address_index=base_adrees+(row)*600*sizeof(int)+col;
*address_index=1;
and also check if (row)>=0 and row<800 and col>=0 and col<600;
yes nick i think u are right..
- ridercoder October 21, 2010and dont depend on setting all bit 0 by calloc because all bit 0 may not represent floating point 0 / NULL so relying on this can make programm non portable .
- ridercoder October 21, 2010A less known difference is that in operating systems with optimistic memory allocation, like Linux, the pointer returned by malloc isn't backed by real memory until the program actually touches it.
calloc does indeed touch the memory (it writes zeroes on it) and thus you'll be sure the OS is backing the allocation with actual RAM (or swap). This is also why it is slower than malloc (not only does it have to zero it, the OS must also find a suitable memory area by possibly swapping out other processes)
In a member function definition, the declaration of a local name hides the declaration of a member of the class with the same name.
The declaration of a member in a derived class hides the declaration of a member of a base class of the same name.
defnition of function in derived class hides base class version fucntion ..
The declaration of the integer x in namespace B hides the character x introduced by the using declaration
- ridercoder October 21, 2010#include<iostream>
using namespace std;
class A{
public:
A(){
cout<<"in a \n";
}
virtual ~A(){
cout<<"out A"<<endl;
}
};
class b:public A{
public:
b(){
cout<<"in B\n"<<endl;
}
~b(){
cout<<"out b"<<endl;
}
};
int main(){
A *bc=new b();
// A *a=new A();
delete bc;
getchar();
}
in constructor i=ii and j=ii
so A x(1,2); //x.i=1 x.j=1 constructor call
A y(3,4); // y.i=3 y.j=3
A z=(x=y);
both x an y are already created so "operator=" is called which does nothing but prints i and j of x;(x is caller of "operator=" here)
z is defined first time so copy constructor is called and i and j of x is printed
(x is argument of copy consturctor)
main (){
int *p;
while(1){
p=(int *)malloc(1024*1024);
if(!p)
printf("no more\n");}
}
output:
aftr some time
no more
no more
no more
.....
so programm will be moved infinite time
void hex(int num){
int rem;
if(!num)
return;
hex(num/16) ;
rem=num%16;
printf("%c",(rem<10)? '0'+rem :('A'+rem-10));
return;
}
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
char *rmv(char *src,const char *ptr){
char *first;
first=strstr(src,ptr);
if(!first)
return src;
else{
cout<<first<<endl;
strcpy(first,first+strlen(ptr));
rmv(src,ptr);
}
return src;
}
int main(){
char s[]="aabbccddccddcc";
const char *p="cc";
char *t;
t=rmv(s,p);
cout<<t;
getchar();
return 0;
}
so can we inharit class and except same behaviour of overloadin?
- ridercoder October 18, 2010int i=100; a.c
extern int i=100; (need not external because global var default to external) b.c
static int i=100; c.c
so a.c and b.c have multiple definition of variable i .. and c.c can use
his i (static scope is in file only );
so compile time error due to a.c and b.c
#include <unistd.h>
int lockf(int fildes, int function, off_t size);
we can also use COPY CONSTRUCTOR in struct??
- ridercoder October 17, 2010we can use concept
suppose if b>a then below concept can give b as output
c is average of a and b(in between) ;
d---> distance between avg and number(a or b);
c=(a+b)/2;
d=abs(a-b)/2;
so max number will be (c+d)..
a--------c--------b
<---d--->|<--d---->
so max that is b is (c+d);
for three number now get between b and another number using same concept.
what if class contain virtual function . then "this" pointer points to virtual table .
is not this also sets virtual ptr to 0?? plz correct me
char *a[]={"cat","rat","rohit"};
size_t len=sizeof(a)/sizeof(char *);
//len=sizeof(name of array)/sizeof(typeofarray);
we can use strtok for this
#include<stdio.h>
#include<string.h>
int main(){
char str[]="hello-this is rider";
char *pch;
reverse(str);
pch=strtok(str," ,."); //we can add more spacial character
while(pch!=null){
printf("%s",pch);
pch=strtok(str," ,.")
}
}
reverse(char *str){
// code to reverse string
}
if u will fallow STANDARD C AIRTHMATIC CONVERSION RULE LOWER TYPE WILL BE UPGRADED TO HIGHER TYPE .
if one is signed int and one is unsigned both will be upgraded to unsigned so result will b 4294967282 correctly.
to use class static variable we have to use scope resolution operator
- ridercoder October 17, 2010# define swap(x,y) /
{ void *_tmp=malloc(sizeof(x)); /
void *_x=&x; void *_y=&y; /
memcpy(tmp,_x,sizeof(x));/
memcpy(_x,_y,sizeof(x));/
memcpy(_y,_tmp,sizeof(x));}
and in GCC we can do :
#define swap(x,y) {typeof(x) _tmp=x,x=y,y=_tmp}
FLOAT WILL BE PRINTED IN IEEE FORMAT
- ridercoder October 16, 2010THIS CODE IS WORK FOR ALL WHETHER IT IS DECIMAL OR FLOAT
{
{
{
#include <iostream>
#include <string>
using namespace std;
int main()
{
float dec = 7.5;
string binary = "";
char *c=(char *)&dec;
int var_size=sizeof(dec); //calculate size of decimal number
for(int i=0;i<var_size;i++){ // loop to traverse each byte of number
char num = *c;
for(int x=0;x<8;x++) // find each bit in a byte
{
if ((num & 1) == 1)
{
binary = "1" + binary;
}
else
{
binary = "0" + binary;
}
num >>= 1;
}
c++;
}
cout << binary << endl;
getchar();
}
}
}
}
#include<stdio.h>
int main()
{
int n, rem, num, i=1;
printf("enter no\n");
scanf("%d", &n);
while(n>0 )
{
rem = n % 2;
n = n/2;
num = (rem * i)+num;
i = i * 10;
}
printf("binary no: %d", num);
}
Unfortunately, there is no standard or portable way. (Some compilers provide nonstandard extensions.) If you need to know, you'll have to keep track of it yourself.ex some compiler have malloc.h header in which _msize()function to get size.
but The malloc function allocates a memory block of at least size bytes. The block may be larger than size bytes because of space required for alignment and maintenance information
so its implementation dependet ...
BUT HOW FREE() KNOWS how much memory to free?
sol-> when we request memory from malloc . compiler writes some info about total size ,checksum etc just before memory allocated for malloc and free uses that information to free memory. it gets ptr and read memory just befor that to get info
how much to free
Kadane’s Algorithm:
Initialize:
max_so_far = 0
max_ending_here = 0
Loop for each element of the array
(a) max_ending_here = max_ending_here + a[i]
(b) if(max_ending_here < 0)
max_ending_here = 0
(c) if(max_so_far < max_ending_here)
max_so_far = max_ending_here
return max_so_far
can we add if(leftTree ^ rightTree)
return false;
in place of if (!leftTree && rightTree) return false;
if (!rightTree && leftTree) return false;
in above code
Shared memory is without question the fastest IPC mechanism that Unix provides. By having processes map the same block of memory, information transfer is almost immediate
- ridercoder November 14, 2010