解题思路:
给大家一个真正用链表实现的
参考代码:
#include<iostream> #include<cstdio> #include<stdlib.h> #include<algorithm> using namespace std; struct LinkList { int fu; int zheng; LinkList *next; }; LinkList *BuildList() { LinkList *head=NULL; int zheng; int fu; int n=10; while(n--) { cin>>zheng; cin>>fu; LinkList *new_node=(LinkList *)malloc(sizeof(LinkList)); if(new_node==NULL) { cout<<"failed"<<endl; } new_node->zheng =zheng; new_node->fu=fu; LinkList *p; if(head==NULL) { head=new_node; new_node->next=NULL; p=head; } if(p!=NULL) { p->next=new_node; new_node->next=NULL; p=new_node; } } return head; } void Print(LinkList *head) { LinkList *p; p=head; int zheng=0; int fu=0; while(p) { zheng+=p->zheng; fu+=p->fu; p=p->next; } cout<<zheng<<"+"<<fu<<"i"<<endl; } int main() { LinkList *p=BuildList(); Print(p); return 0; }
0.0分
5 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:670 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:463 |
【数组的距离】 (C语言代码)浏览:782 |
1048题解(读入回车问题)浏览:626 |
C语言程序设计教程(第三版)课后习题12.5 (C语言代码)浏览:797 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:657 |
生日日数 (C语言代码)浏览:1565 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:1287 |
C语言程序设计教程(第三版)课后习题7.2 (C++代码)浏览:451 |
C语言训练-自守数问题 (C语言代码)浏览:702 |