background image

List *list_reverse(List *head) 

List *p,*q,*r; 
p=head; 
q=p->next; 
while(q!=NULL) 

r=q->next; 
q->next=p; 
p=q; 
q=r; 

head->next=NULL; 
head=p; 
return head; 

void main(void) 

struct List *head,*p; 
int d; 
head=list_create(); 
printf("\n"); 
for(p=head->next;p;p=p->next) 
printf("--%d--",p->data); 

head=list_reverse(head); 
printf("\n"); 
for(p=head;p->next;p=p->next) 
printf("--%d--",p->data); 
}

       编写函数数 N 个 BYTE 的数据中有多少位是 1。

解:此题按步骤解:先定位到某一个

BYTE 数据;再计算其中有多少个 1。叠加得解。

#incluede<iostream>
#define N 10
//
定义 BYTE 类型别名
#ifndef BYTE
typedef unsigned char BYTE;
#endif