中国大学MOOC: 以下程序执行后的输出结果是#include#includestructNODE{intnum;structNODE*next;};intmain(){structNODE*p,*q,*r;intsum=0;p=(structNODE*)malloc(sizeof(structNODE));q=(structNODE*)malloc(sizeof(structNODE));r=(structNODE*)malloc(sizeof(structNODE));p->num=1;q->num=2;r->num=3;p->next=q;q->next=r;r->next=NULL;sum+=q->next->num;sum+=p->num;printf("%d\n",sum);return0;}
举一反三
- 有以下程序 #include struct NODE {int num; struct NODE *next; } main() {struct NODE *p,*q,*r; p=(struct NODE *)malloc(sizeof(struct NODE)); q=(struct NODE *)malloc(sizeof(struct NODE)); r=(struct NODE *)malloc(sizeof(struct NODE)); p->num=10;q->num=20;r->num=30; p->next=q;q->next=r; printf("%d ",p->num+q->next->num); } 程序运行后的输出结果是( )
- 以下程序运行后的输出结果是 ________ struct NODE { int num; struct NODE *next; } main() { struct NODE s[3], *p, *q, *r; int sum=0; s[0].num=1; s[1].num=2; s[2].num=3; s[0].next=s+1; s[1].next=s+2; s[2].next=s; p=s; q=p->next; r=q->next; sum+=q->next->num; sum+=r->next->next->num; printf("%d", sum); }
- 中国大学MOOC: 下面程序执行后的输出结果是:#include <iostream>#include <cmath>using namespace std;struct NODE {int num; struct NODE *next;};int main(){struct NODE *p,*q,*r;p=new NODE;q=new NODE;r=new NODE;p->num=10; q->num=20; r->num=30;p->next=q;q->next=r;cout<<p->num+q->next->num<<endl; return 0;}
- (2)intBB(LinkList*L){LinkList*p,*q,*r;p=L->next;if(!p)return0;while(p->next){q=p;while(q->next){if(q->next->data!=p->data)q=q->next;else{r=q->next;q->next=r->next;free(r);}}p=p->next;}}Writethefunctionofthealgorithmabove.(5.0分)
- 阅读下列程序段structnode{charinfo;structnode*link;}*top,*p;charc;top=NULL;while((c=getchar())!='\n'){p=(structnode*)malloc(sizeof(structnode));p->info=c;p->link=top;top=p;}while(top){p=top;top=top->link;putchar(p->info);free(p);}若从键盘输入abcdef↙,则输出结果为________。