Charles
BAN USERbool DeleteNode(Linklist *p,int a)
{
static Linklist head=NULL;
if(head==NULL)
{
head=*p;
if(head->data==a)
{
if((*p)->next==NULL)
{
*p=NULL;
return 0;
}
*p=(*p)->next;
free(head);
head=NULL;
return DeleteNode(p,a);
}
}
if((*p)->next==0) return 0;
if(a!=(*p)->next->data)
{
return DeleteNode(&((*p)->next),a);
}
else
{
Linklist q=(*p)->next;
(*p)->next=q->next;
free((q));
if((*p)->next!=NULL)
{
return DeleteNode(&((*p)->next),a);
}
}
return 1;
}
Recursive version
bool DeleteNode(Linklist p,int a)
{
static Linklist head=NULL;
if(head==NULL)
{
head=p;
if(head->data==a)
{
return 1;
}
}
if(p==NULL) return 0;
if(p->next==0) return 0;
if(a!=p->next->data)
{
return DeleteNode(p->next,a);
}
else
{
Linklist q=p->next;
p->next=q->next;
free(q);
return 1;
}
}
the above answer is wrong! I don't understand why someone vote it ,
what Anonymous described should be something like this :
{
void (*abc)(int, void (*def)());
}
but ...
Note void (*abc(...))(), what does this mean is abc return pointer to a function which take no args and return void, that is what abc is ,abc take a function pointer and return the same type of function pointer,
you can do this
{
void(*def)();
void (*abc(int, void(*def)()))();
def=(*abc)(0,def);
}
to simplify this ,we can use typedef
{
typedef void(*q)();
typedef q (*p)(int,q);
// then we can do something like below:
q b;
p a;
b=(*a)(0,b);
}
- Charles December 28, 2013-1
too slow , it is not efficient();
unsigned int copyfile(FILE *p, FILE *q)
{
char buf[4096]={0};
int readbytes=0,writebytes=0;
int count=0;
//fseek(p,0,SEEK_SET);
while(readbytes=fread(buf,1,4096,p))
{
if((readbytes!=4096)&&(!feof(p)))
{
printf("%d",ferror(p));
return 0;
}
if(writebytes=fwrite(buf,1,readbytes,q))
{
if(writebytes!=readbytes)
{
printf("%d",ferror(q));
return 0;
}
count=count+writebytes;
}
if(readbytes!=4096) break;
}
return count;
}
}
- Charles December 28, 2013DWORD SUBARRAY(DWORD *ARR,DWORD SIZE)
{
INT I=0;
CREATESEMPHORE(FREETHREADCNT,N)
WHILE(I<M)
{
WAITFORSINGLEOBJECT(FREETHREADCNT,INFINITE)
IF(I=M-1)&&(I%2!=0)
{
CREATETHREAD(TSUM,ARR[I],0);
I++;
}
ELSE
{
CREATETHREAD(TSUM,ARR[I],ARR[I+1]);
I=I+2;
}
}
}
VOLITLE DWORD SUM=0;
VOID TSUM(DWORD A, DWORD B)
{
ATOMICADD(SUM,A+B)
RELEASESEMAPHORE(FREETHREADCNT)
}
- Charles December 28, 2013