Q2.4
来源:互联网 发布:少年西游记手游源码 编辑:程序博客网 时间:2024/05/01 08:16
#include <iostream>using namespace std;typedef struct Node{int data;struct Node* next;}Node, *pNode;pNode Init(int* a, int len){int i;pNode head, p, q;head = new Node();head->data = a[0];q = head;for (i = 1; i < len; ++i){p = new Node();p->data = a[i];q->next = p;q = p;}q->next = NULL;return head;}void printList(pNode p){while(p){cout<<p->data<<" ";if (p->next){p = p->next;}else{cout<<endl;break;}}}void addList(pNode aList, pNode bList, pNode cList){pNode p1, p2, re, newOne;int up = 0;p1 = aList;p2 = bList;re = cList;while(p1 && p2){newOne = new Node();re->next = newOne;re = newOne;if (p1->data + p2->data + up >= 10){re->data = p1->data + p2->data + up - 10;up = 1;}else{re->data = p1->data + p2->data + up;up = 0;}p1 = p1->next;p2 = p2->next;}while(p1){newOne = new Node();re->next = newOne;re = newOne;if (p1->data + up >= 10){re->data = p1->data + up - 10;up = 1;}else{re->data = p1->data + up;up = 0;}p1 = p1->next;}while(p2){newOne = new Node();re->next = newOne;re = newOne;if (p2->data + up >= 10){re->data = p2->data + up - 10;up = 1;}else{re->data = p2->data + up;up = 0;}p2 = p2->next;}re->next = NULL;}int main(void){pNode aList, bList, cList;int a[] = {3, 1, 5, 3, 2};int b[] = {5, 9, 2, 7};aList = Init(a, sizeof(a) / sizeof(int));bList = Init(b, sizeof(b) / sizeof(int));cList = new Node();addList(aList, bList, cList);printList(aList);printList(bList);printList(cList->next);return 0;}
0 0
- Q2.4
- Q2.4 Partition List
- Cracking the coding interview--Q2.4
- Cracking the coding interview--Q2.4
- 【CareerCup】 Linked Lists—Q2.4
- 【CareerCup】 Linked Lists—Q2.4
- Cracking the coding interview--Q2.4
- cci-Q2.4 链表的值相加
- Q2.3
- Q2.5
- LeetCode Q2
- Unladen Swallow 2009Q2
- 中文搜索引擎2010Q2市场份额
- [Python Challenge] - Q2
- Project Euler Q2 解法
- 2016-Q2 BUG清单
- Q2.Add Two Numbers
- Q2--替换空格
- 2014-03-04
- 皇冠3D成型與最流行使用的材料
- Q2.3
- Windows7 64位系统搭建Cocos2d-x-2.2.1最新版以及Android交叉编译环境(详细教程)
- 从hadoop框架与MapReduce模式中谈海量数据处理
- Q2.4
- ubuntu安装使用笔记04——jdk安装
- 简单列表的实现(基于链表)
- 数学对象
- 程序员,闯天下----一个文科生的10年编程之旅和创业之路
- Request的getParameter和getAttribute方法的区别
- weka连接数据库方法(mysql)
- fork,vfork,clone与pthread_create之间的区别
- MFC 三类消息